Skip to content

Commit 7001cec

Browse files
committed
sweepbatcher: cancel spendCtx after processing
Function monitorSpendAndNotify used to cancel the context passed to RegisterSpendNtfn right after starting the goroutine processing results. Spend notifications were missed. Now the context is canceled when the goroutine finishes.
1 parent b7f9127 commit 7001cec

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sweepbatcher/sweep_batcher.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,12 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweep *sweep,
11291129
parentBatchID int32, notifier *SpendNotifier) error {
11301130

11311131
spendCtx, cancel := context.WithCancel(ctx)
1132-
defer cancel()
11331132

11341133
// Then we get the total amount that was swept by the batch.
11351134
totalSwept, err := b.store.TotalSweptAmount(ctx, parentBatchID)
11361135
if err != nil {
1136+
cancel()
1137+
11371138
return err
11381139
}
11391140

@@ -1142,11 +1143,14 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweep *sweep,
11421143
sweep.initiationHeight,
11431144
)
11441145
if err != nil {
1146+
cancel()
1147+
11451148
return err
11461149
}
11471150

11481151
b.wg.Add(1)
11491152
go func() {
1153+
defer cancel()
11501154
defer b.wg.Done()
11511155
infof("Batcher monitoring spend for swap %x",
11521156
sweep.swapHash[:6])

0 commit comments

Comments
 (0)