mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 15:40:59 +02:00
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:
@@ -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")
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user