Skip to content

Commit 2de9f4f

Browse files
committed
sweepbatcher: close the quit channel when the batcher is shutting down
1 parent 08e4b0a commit 2de9f4f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

sweepbatcher/sweep_batch.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ type batch struct {
197197
// main event loop.
198198
callLeave chan struct{}
199199

200-
// quit signals that the batch must stop.
200+
// stopped signals that the batch has stopped.
201+
stopped chan struct{}
202+
203+
// quit is owned by the parent batcher and signals that the batch must
204+
// stop.
201205
quit chan struct{}
202206

203207
// wallet is the wallet client used to create and publish the batch
@@ -261,6 +265,7 @@ type batchKit struct {
261265
purger Purger
262266
store BatcherStore
263267
log btclog.Logger
268+
quit chan struct{}
264269
}
265270

266271
// scheduleNextCall schedules the next call to the batch handler's main event
@@ -270,6 +275,9 @@ func (b *batch) scheduleNextCall() (func(), error) {
270275
case b.callEnter <- struct{}{}:
271276

272277
case <-b.quit:
278+
return func() {}, ErrBatcherShuttingDown
279+
280+
case <-b.stopped:
273281
return func() {}, ErrBatchShuttingDown
274282
}
275283

@@ -293,7 +301,8 @@ func NewBatch(cfg batchConfig, bk batchKit) *batch {
293301
errChan: make(chan error, 1),
294302
callEnter: make(chan struct{}),
295303
callLeave: make(chan struct{}),
296-
quit: make(chan struct{}),
304+
stopped: make(chan struct{}),
305+
quit: bk.quit,
297306
batchTxid: bk.batchTxid,
298307
wallet: bk.wallet,
299308
chainNotifier: bk.chainNotifier,
@@ -320,7 +329,8 @@ func NewBatchFromDB(cfg batchConfig, bk batchKit) *batch {
320329
errChan: make(chan error, 1),
321330
callEnter: make(chan struct{}),
322331
callLeave: make(chan struct{}),
323-
quit: make(chan struct{}),
332+
stopped: make(chan struct{}),
333+
quit: bk.quit,
324334
batchTxid: bk.batchTxid,
325335
batchPkScript: bk.batchPkScript,
326336
rbfCache: bk.rbfCache,
@@ -447,7 +457,7 @@ func (b *batch) Run(ctx context.Context) error {
447457
runCtx, cancel := context.WithCancel(ctx)
448458
defer func() {
449459
cancel()
450-
close(b.quit)
460+
close(b.stopped)
451461
b.wg.Wait()
452462
}()
453463

sweepbatcher/sweep_batcher.go

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (b *Batcher) Run(ctx context.Context) error {
216216
runCtx, cancel := context.WithCancel(ctx)
217217
defer func() {
218218
cancel()
219+
close(b.quit)
219220

220221
for _, batch := range b.batches {
221222
batch.Wait()
@@ -379,6 +380,7 @@ func (b *Batcher) spinUpBatch(ctx context.Context) (*batch, error) {
379380
verifySchnorrSig: b.VerifySchnorrSig,
380381
purger: b.AddSweep,
381382
store: b.store,
383+
quit: b.quit,
382384
}
383385

384386
batch := NewBatch(cfg, batchKit)
@@ -461,6 +463,7 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
461463
purger: b.AddSweep,
462464
store: b.store,
463465
log: batchPrefixLogger(fmt.Sprintf("%d", batch.id)),
466+
quit: b.quit,
464467
}
465468

466469
cfg := batchConfig{

0 commit comments

Comments
 (0)