Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: shutdown chanrouter correctly. #8497

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion chainntnfs/bitcoindnotify/bitcoind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
ziggie1984 marked this conversation as resolved.
Show resolved Hide resolved
}

// Stop the mempool notifier.
b.memNotifier.TearDown()
Expand Down
7 changes: 6 additions & 1 deletion chainntnfs/neutrinonotify/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions chanfitness/chaneventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,17 @@ func (c *ChannelEventStore) Stop() error {

// Stop the ticker after the goroutine reading from it has exited, to
// avoid a race.
c.cfg.FlapCountTicker.Stop()
var err error
if c.cfg.FlapCountTicker == nil {
ziggie1984 marked this conversation as resolved.
Show resolved Hide resolved
err = fmt.Errorf("ChannelEventStore FlapCountTicker not " +
"initialized")
} else {
c.cfg.FlapCountTicker.Stop()
}

log.Debugf("ChannelEventStore shutdown complete")

return nil
return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non blocking: i'd say this is an error worth logging but not returning. The Stop function itself did not error here, it was just that Start never ran/completed. cause this makes it seem like "error stopping chanEventStore" even though there wasnt really an error stopping it. But defs not a big deal

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment for a few other spots in this commit

}

// addChannel checks whether we are already tracking a channel's peer, creates a
Expand Down
7 changes: 6 additions & 1 deletion discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,12 @@ 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 in the case where the `Stop` method is
// called when the `Start` method does not complete.
if d.blockEpochs != nil {
ziggie1984 marked this conversation as resolved.
Show resolved Hide resolved
d.blockEpochs.Cancel()
}

d.syncMgr.Stop()

Expand Down
6 changes: 5 additions & 1 deletion htlcswitch/interceptable_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
14 changes: 9 additions & 5 deletions htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions invoices/invoiceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,21 @@ func (i *InvoiceRegistry) Stop() error {
log.Info("InvoiceRegistry shutting down...")
defer log.Debug("InvoiceRegistry shutdown complete")

i.expiryWatcher.Stop()
var err error
if i.expiryWatcher == nil {
err = fmt.Errorf("InvoiceRegistry expiryWatcher is not " +
"initialized")
} else {
i.expiryWatcher.Stop()
}

close(i.quit)

i.wg.Wait()

log.Debug("InvoiceRegistry shutdown complete")

return nil
return err
}

// invoiceEvent represents a new event that has modified on invoice on disk.
Expand Down
4 changes: 3 additions & 1 deletion lnwallet/chainfee/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,9 @@ func (w *WebAPIEstimator) Stop() error {
return nil
}

w.updateFeeTicker.Stop()
if w.updateFeeTicker != nil {
w.updateFeeTicker.Stop()
}

close(w.quit)
w.wg.Wait()
Expand Down
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,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
Expand Down
4 changes: 4 additions & 0 deletions tor/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ func (c *Controller) Stop() error {
// Reset service ID.
c.activeServiceID = ""

if c.conn == nil {
return fmt.Errorf("no connection available to the tor server")
}

return c.conn.Close()
}

Expand Down