From 0bd76ffe32edf1f5a019b00ca78951ed7cb4c92f Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 24 Sep 2024 14:44:09 +0900 Subject: [PATCH] invoices: init quit channel of modifier Also add atomic start and stop vars to prevent close of a closed channel. --- invoices/modification_interceptor.go | 12 ++++++++++++ server.go | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/invoices/modification_interceptor.go b/invoices/modification_interceptor.go index e2d9a9051..47f0de80b 100644 --- a/invoices/modification_interceptor.go +++ b/invoices/modification_interceptor.go @@ -66,6 +66,9 @@ func (s *safeCallback) Exec(req HtlcModifyRequest) (*HtlcModifyResponse, // settle an invoice, enabling a subscribed client to modify certain aspects of // those HTLCs. type HtlcModificationInterceptor struct { + started atomic.Bool + stopped atomic.Bool + // callback is the wrapped client callback function that is called when // an invoice is intercepted. This function gives the client the ability // to determine how the invoice should be settled. @@ -79,6 +82,7 @@ type HtlcModificationInterceptor struct { func NewHtlcModificationInterceptor() *HtlcModificationInterceptor { return &HtlcModificationInterceptor{ callback: &safeCallback{}, + quit: make(chan struct{}), } } @@ -163,11 +167,19 @@ func (s *HtlcModificationInterceptor) RegisterInterceptor( // Start starts the service. func (s *HtlcModificationInterceptor) Start() error { + if !s.started.CompareAndSwap(false, true) { + return nil + } + return nil } // Stop stops the service. func (s *HtlcModificationInterceptor) Stop() error { + if !s.stopped.CompareAndSwap(false, true) { + return nil + } + close(s.quit) return nil diff --git a/server.go b/server.go index 4097233e0..d099fc931 100644 --- a/server.go +++ b/server.go @@ -2411,6 +2411,10 @@ func (s *server) Stop() error { if err := s.invoices.Stop(); err != nil { srvrLog.Warnf("failed to stop invoices: %v", err) } + if err := s.invoiceHtlcModifier.Stop(); err != nil { + srvrLog.Warnf("failed to stop htlc invoices "+ + "modifier: %v", err) + } if err := s.chanRouter.Stop(); err != nil { srvrLog.Warnf("failed to stop chanRouter: %v", err) }