Skip to content

Commit

Permalink
multi: make sure missionControlStore catches done signal
Browse files Browse the repository at this point in the history
This commit makes sure `missionControlStore` catches the shutdown signal
when draining the ticker. A few debug logs are added to aid the process.
  • Loading branch information
yyforyongyu committed Jul 15, 2024
1 parent 7c17077 commit c064421
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ func (d *AuthenticatedGossiper) Stop() error {
}

func (d *AuthenticatedGossiper) stop() {
log.Info("Authenticated Gossiper is stopping")
defer log.Info("Authenticated Gossiper stopped")
log.Debug("Authenticated Gossiper is stopping")
defer log.Debug("Authenticated Gossiper stopped")

d.blockEpochs.Cancel()

Expand Down
3 changes: 3 additions & 0 deletions htlcswitch/decayedlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (d *DecayedLog) initBuckets() error {

// Stop halts the garbage collector and closes boltdb.
func (d *DecayedLog) Stop() error {
log.Debugf("DecayedLog shutting down...")
defer log.Debugf("DecayedLog shutdown complete")

if !atomic.CompareAndSwapInt32(&d.stopped, 0, 1) {
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions routing/chainview/bitcoind.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func (b *BitcoindFilteredChainView) Start() error {
//
// NOTE: This is part of the FilteredChainView interface.
func (b *BitcoindFilteredChainView) Stop() error {
log.Debug("BitcoindFilteredChainView stopping")
defer log.Debug("BitcoindFilteredChainView stopped")

// Already shutting down?
if atomic.AddInt32(&b.stopped, 1) != 1 {
return nil
Expand All @@ -136,8 +139,6 @@ func (b *BitcoindFilteredChainView) Stop() error {

b.blockQueue.Stop()

log.Infof("FilteredChainView stopping")

close(b.quit)
b.wg.Wait()

Expand Down
5 changes: 3 additions & 2 deletions routing/chainview/btcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (b *BtcdFilteredChainView) Start() error {
//
// NOTE: This is part of the FilteredChainView interface.
func (b *BtcdFilteredChainView) Stop() error {
log.Debug("BtcdFilteredChainView stopping")
defer log.Debug("BtcdFilteredChainView stopped")

// Already shutting down?
if atomic.AddInt32(&b.stopped, 1) != 1 {
return nil
Expand All @@ -146,8 +149,6 @@ func (b *BtcdFilteredChainView) Stop() error {

b.blockQueue.Stop()

log.Infof("FilteredChainView stopping")

close(b.quit)
b.wg.Wait()

Expand Down
5 changes: 3 additions & 2 deletions routing/chainview/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ func (c *CfFilteredChainView) Start() error {
//
// NOTE: This is part of the FilteredChainView interface.
func (c *CfFilteredChainView) Stop() error {
log.Debug("CfFilteredChainView stopping")
defer log.Debug("CfFilteredChainView stopped")

// Already shutting down?
if atomic.AddInt32(&c.stopped, 1) != 1 {
return nil
}

log.Infof("FilteredChainView stopping")

close(c.quit)
c.blockQueue.Stop()
c.wg.Wait()
Expand Down
13 changes: 11 additions & 2 deletions routing/missioncontrol_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ func (b *missionControlStore) run() {
// channel needs to be drained appropriately. This could happen
// if the flushInterval is very small (e.g. 1 nanosecond).
if !timer.Stop() {
<-timer.C
select {
case <-timer.C:
case <-b.done:
log.Debugf("Stopping mission control store")
}
}

for {
Expand Down Expand Up @@ -335,7 +339,12 @@ func (b *missionControlStore) run() {
case <-b.done:
// Release the timer's resources.
if !timer.Stop() {
<-timer.C
select {
case <-timer.C:
case <-b.done:
log.Debugf("Mission control " +
"store stopped")
}
}
return
}
Expand Down

0 comments on commit c064421

Please sign in to comment.