Skip to content

Commit 0bd76ff

Browse files
committed
invoices: init quit channel of modifier
Also add atomic start and stop vars to prevent close of a closed channel.
1 parent 7dc86ac commit 0bd76ff

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

invoices/modification_interceptor.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func (s *safeCallback) Exec(req HtlcModifyRequest) (*HtlcModifyResponse,
6666
// settle an invoice, enabling a subscribed client to modify certain aspects of
6767
// those HTLCs.
6868
type HtlcModificationInterceptor struct {
69+
started atomic.Bool
70+
stopped atomic.Bool
71+
6972
// callback is the wrapped client callback function that is called when
7073
// an invoice is intercepted. This function gives the client the ability
7174
// to determine how the invoice should be settled.
@@ -79,6 +82,7 @@ type HtlcModificationInterceptor struct {
7982
func NewHtlcModificationInterceptor() *HtlcModificationInterceptor {
8083
return &HtlcModificationInterceptor{
8184
callback: &safeCallback{},
85+
quit: make(chan struct{}),
8286
}
8387
}
8488

@@ -163,11 +167,19 @@ func (s *HtlcModificationInterceptor) RegisterInterceptor(
163167

164168
// Start starts the service.
165169
func (s *HtlcModificationInterceptor) Start() error {
170+
if !s.started.CompareAndSwap(false, true) {
171+
return nil
172+
}
173+
166174
return nil
167175
}
168176

169177
// Stop stops the service.
170178
func (s *HtlcModificationInterceptor) Stop() error {
179+
if !s.stopped.CompareAndSwap(false, true) {
180+
return nil
181+
}
182+
171183
close(s.quit)
172184

173185
return nil

server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,6 +2411,10 @@ func (s *server) Stop() error {
24112411
if err := s.invoices.Stop(); err != nil {
24122412
srvrLog.Warnf("failed to stop invoices: %v", err)
24132413
}
2414+
if err := s.invoiceHtlcModifier.Stop(); err != nil {
2415+
srvrLog.Warnf("failed to stop htlc invoices "+
2416+
"modifier: %v", err)
2417+
}
24142418
if err := s.chanRouter.Stop(); err != nil {
24152419
srvrLog.Warnf("failed to stop chanRouter: %v", err)
24162420
}

0 commit comments

Comments
 (0)