diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index 2bffefdbefd..f0547e4dfb3 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -151,7 +151,12 @@ func (b *BitcoindNotifier) Stop() error { close(epochClient.epochChan) } - b.txNotifier.TearDown() + + // The txNotifier is only initialized in the start method therefore we + // need to make sure we don't access a nil pointer here. + if b.txNotifier != nil { + b.txNotifier.TearDown() + } // Stop the mempool notifier. b.memNotifier.TearDown() diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index 80e210c2fd8..55d92357797 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -152,7 +152,12 @@ func (n *NeutrinoNotifier) Stop() error { close(epochClient.epochChan) } - n.txNotifier.TearDown() + + // The txNotifier is only initialized in the start method therefore we + // need to make sure we don't access a nil pointer here. + if n.txNotifier != nil { + n.txNotifier.TearDown() + } return nil } diff --git a/chanfitness/chaneventstore.go b/chanfitness/chaneventstore.go index 4b1dc1ddd0b..e5464b57621 100644 --- a/chanfitness/chaneventstore.go +++ b/chanfitness/chaneventstore.go @@ -226,7 +226,10 @@ func (c *ChannelEventStore) Stop() error { // Stop the ticker after the goroutine reading from it has exited, to // avoid a race. - c.cfg.FlapCountTicker.Stop() + if c.cfg.FlapCountTicker == nil { + return fmt.Errorf("ChannelEventStore FlapCountTicker not " + + "initialized") + } log.Debugf("ChannelEventStore shutdown complete") diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 53bfd38c2af..b3e4d1fb1fa 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -753,7 +753,11 @@ func (d *AuthenticatedGossiper) stop() { log.Debug("Authenticated Gossiper is stopping") defer log.Debug("Authenticated Gossiper stopped") - d.blockEpochs.Cancel() + // `blockEpochs` is only initialized in the start routine so we make + // sure we don't panic here. + if d.blockEpochs != nil { + d.blockEpochs.Cancel() + } d.syncMgr.Stop() diff --git a/htlcswitch/interceptable_switch.go b/htlcswitch/interceptable_switch.go index 144af814abc..0ac19a36cdc 100644 --- a/htlcswitch/interceptable_switch.go +++ b/htlcswitch/interceptable_switch.go @@ -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") diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index 57b536055f5..15504c62a81 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -261,6 +261,11 @@ func (i *InvoiceRegistry) Stop() error { log.Info("InvoiceRegistry shutting down...") defer log.Debug("InvoiceRegistry shutdown complete") + if i.expiryWatcher == nil { + return fmt.Errorf("InvoiceRegistry expiryWatcher not " + + "initialized") + } + i.expiryWatcher.Stop() close(i.quit) diff --git a/server.go b/server.go index c3260518b02..9ef6a2491c5 100644 --- a/server.go +++ b/server.go @@ -2107,6 +2107,9 @@ func (s *server) Start() error { } } + // chanSubSwapper must be started after the `channelNotifier` + // because it depends on channel events as a synchronization + // point. cleanup = cleanup.add(s.chanSubSwapper.Stop) if err := s.chanSubSwapper.Start(); err != nil { startErr = err