multi: make sure missionControlStore catches done signal

This commit makes sure `missionControlStore` catches the shutdown signal
when draining the ticker. A few debug logs are added to aid the process.
This commit is contained in:
yyforyongyu
2024-07-16 01:04:36 +08:00
parent 50279464ad
commit 2608c0893e
6 changed files with 25 additions and 10 deletions

View File

@@ -750,8 +750,8 @@ func (d *AuthenticatedGossiper) Stop() error {
} }
func (d *AuthenticatedGossiper) stop() { func (d *AuthenticatedGossiper) stop() {
log.Info("Authenticated Gossiper is stopping") log.Debug("Authenticated Gossiper is stopping")
defer log.Info("Authenticated Gossiper stopped") defer log.Debug("Authenticated Gossiper stopped")
d.blockEpochs.Cancel() d.blockEpochs.Cancel()

View File

@@ -149,6 +149,9 @@ func (d *DecayedLog) initBuckets() error {
// Stop halts the garbage collector and closes boltdb. // Stop halts the garbage collector and closes boltdb.
func (d *DecayedLog) Stop() error { func (d *DecayedLog) Stop() error {
log.Debugf("DecayedLog shutting down...")
defer log.Debugf("DecayedLog shutdown complete")
if !atomic.CompareAndSwapInt32(&d.stopped, 0, 1) { if !atomic.CompareAndSwapInt32(&d.stopped, 0, 1) {
return nil return nil
} }

View File

@@ -125,6 +125,9 @@ func (b *BitcoindFilteredChainView) Start() error {
// //
// NOTE: This is part of the FilteredChainView interface. // NOTE: This is part of the FilteredChainView interface.
func (b *BitcoindFilteredChainView) Stop() error { func (b *BitcoindFilteredChainView) Stop() error {
log.Debug("BitcoindFilteredChainView stopping")
defer log.Debug("BitcoindFilteredChainView stopped")
// Already shutting down? // Already shutting down?
if atomic.AddInt32(&b.stopped, 1) != 1 { if atomic.AddInt32(&b.stopped, 1) != 1 {
return nil return nil
@@ -136,8 +139,6 @@ func (b *BitcoindFilteredChainView) Stop() error {
b.blockQueue.Stop() b.blockQueue.Stop()
log.Infof("FilteredChainView stopping")
close(b.quit) close(b.quit)
b.wg.Wait() b.wg.Wait()

View File

@@ -135,6 +135,9 @@ func (b *BtcdFilteredChainView) Start() error {
// //
// NOTE: This is part of the FilteredChainView interface. // NOTE: This is part of the FilteredChainView interface.
func (b *BtcdFilteredChainView) Stop() error { func (b *BtcdFilteredChainView) Stop() error {
log.Debug("BtcdFilteredChainView stopping")
defer log.Debug("BtcdFilteredChainView stopped")
// Already shutting down? // Already shutting down?
if atomic.AddInt32(&b.stopped, 1) != 1 { if atomic.AddInt32(&b.stopped, 1) != 1 {
return nil return nil
@@ -146,8 +149,6 @@ func (b *BtcdFilteredChainView) Stop() error {
b.blockQueue.Stop() b.blockQueue.Stop()
log.Infof("FilteredChainView stopping")
close(b.quit) close(b.quit)
b.wg.Wait() b.wg.Wait()

View File

@@ -135,13 +135,14 @@ func (c *CfFilteredChainView) Start() error {
// //
// NOTE: This is part of the FilteredChainView interface. // NOTE: This is part of the FilteredChainView interface.
func (c *CfFilteredChainView) Stop() error { func (c *CfFilteredChainView) Stop() error {
log.Debug("CfFilteredChainView stopping")
defer log.Debug("CfFilteredChainView stopped")
// Already shutting down? // Already shutting down?
if atomic.AddInt32(&c.stopped, 1) != 1 { if atomic.AddInt32(&c.stopped, 1) != 1 {
return nil return nil
} }
log.Infof("FilteredChainView stopping")
close(c.quit) close(c.quit)
c.blockQueue.Stop() c.blockQueue.Stop()
c.wg.Wait() c.wg.Wait()

View File

@@ -303,7 +303,11 @@ func (b *missionControlStore) run() {
// channel needs to be drained appropriately. This could happen // channel needs to be drained appropriately. This could happen
// if the flushInterval is very small (e.g. 1 nanosecond). // if the flushInterval is very small (e.g. 1 nanosecond).
if !timer.Stop() { if !timer.Stop() {
<-timer.C select {
case <-timer.C:
case <-b.done:
log.Debugf("Stopping mission control store")
}
} }
for { for {
@@ -335,7 +339,12 @@ func (b *missionControlStore) run() {
case <-b.done: case <-b.done:
// Release the timer's resources. // Release the timer's resources.
if !timer.Stop() { if !timer.Stop() {
<-timer.C select {
case <-timer.C:
case <-b.done:
log.Debugf("Mission control " +
"store stopped")
}
} }
return return
} }