Skip to content

Commit 01664ad

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 2f05934 commit 01664ad

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
@@ -1128,11 +1128,12 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweep *sweep,
11281128
parentBatchID int32, notifier *SpendNotifier) error {
11291129

11301130
spendCtx, cancel := context.WithCancel(ctx)
1131-
defer cancel()
11321131

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

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

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

0 commit comments

Comments
 (0)