multi: prevent nil panics in stop methods.

With this PR we might call the stop method even when the start
method of a subsystem did not successfully finish therefore we
need to make sure we guard the stop methods for potential panics
if some variables are not initialized in the contructors of the
subsystems.
This commit is contained in:
ziggie
2024-07-27 14:39:46 +02:00
parent e19f891453
commit 02c1264c53
10 changed files with 58 additions and 14 deletions

View File

@@ -242,7 +242,11 @@ func (s *InterceptableSwitch) Stop() error {
close(s.quit)
s.wg.Wait()
s.blockEpochStream.Cancel()
// We need to check whether the start routine run and initialized the
// `blockEpochStream`.
if s.blockEpochStream != nil {
s.blockEpochStream.Cancel()
}
log.Debug("InterceptableSwitch shutdown complete")

View File

@@ -562,14 +562,18 @@ func (l *channelLink) Stop() {
}
// Ensure the channel for the timer is drained.
if !l.updateFeeTimer.Stop() {
select {
case <-l.updateFeeTimer.C:
default:
if l.updateFeeTimer != nil {
if !l.updateFeeTimer.Stop() {
select {
case <-l.updateFeeTimer.C:
default:
}
}
}
l.hodlQueue.Stop()
if l.hodlQueue != nil {
l.hodlQueue.Stop()
}
close(l.quit)
l.wg.Wait()