From 34bb0ec36f9fe6bf8c44791402c185b5136fc5a2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 30 Jul 2017 14:21:49 -0700 Subject: [PATCH] server: within peerTerminationWatcher exit early if daemon is exiting --- server.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 65e0b8a0..b39ab6e8 100644 --- a/server.go +++ b/server.go @@ -336,8 +336,8 @@ func (s *server) Start() error { s.wg.Add(1) go s.queryHandler() - // With all the relevant sub-systems started, we'll now atetmpt to - // stasblish persistent connections to our direct channel collaborators + // With all the relevant sub-systems started, we'll now attempt to + // establish persistent connections to our direct channel collaborators // within the network. if err := s.establishPersistentConnections(); err != nil { return err @@ -610,9 +610,21 @@ func (s *server) peerTerminationWatcher(p *peer) { srvrLog.Debugf("Peer %v has been disconnected", p) + // If the server is exiting then we can bail out early ourselves as all + // the other sub-systems will already be shutting down. + select { + case <-s.quit: + return + default: + // If we aren't shutting down, then we'll fall through this + // this empty default case. + } + // Tell the switch to remove all links associated with this peer. // Passing nil as the target link indicates that all links associated // with this interface should be closed. + // + // TODO(roasbeef): instead add a PurgeInterfaceLinks function? links, err := p.server.htlcSwitch.GetLinksByInterface(p.pubKeyBytes) if err != nil { srvrLog.Errorf("unable to get channel links: %v", err)