Skip to content

Commit 1b6213a

Browse files
committed
htlcswitch: stop InvoiceRegistry in newMockRegistry cleanup
newMockRegistry started an InvoiceRegistry but never stopped it. InvoiceRegistry internally starts two background goroutines — invoiceEventLoop and the InvoiceExpiryWatcher mainLoop — that run for the lifetime of the registry. Without a matching Stop() call both goroutines leaked for every test that called newMockRegistry, accumulating thousands of goroutines during fuzzing. Register a t.Cleanup to call registry.Stop() so both loops are torn down when the test ends.
1 parent 2f150c9 commit 1b6213a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

htlcswitch/mock.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@ func newMockRegistry(t testing.TB) *mockInvoiceRegistry {
10191019
},
10201020
)
10211021
registry.Start()
1022+
t.Cleanup(func() {
1023+
if err := registry.Stop(); err != nil {
1024+
t.Errorf("registry.Stop: %v", err)
1025+
}
1026+
})
10221027

10231028
return &mockInvoiceRegistry{
10241029
registry: registry,

0 commit comments

Comments
 (0)