peer: drain chans before exiting peerHandler
Also disconnect the failed peer to allow the peerDoneHandler goroutine to exit, instead of hanging around. Fixes #583.
This commit is contained in:
parent
e24fe94f58
commit
7996eb1f9d
1 changed files with 18 additions and 1 deletions
19
server.go
19
server.go
|
@ -1494,7 +1494,7 @@ func (s *server) peerConnHandler(sp *serverPeer) {
|
|||
err := s.establishConn(sp)
|
||||
if err != nil {
|
||||
srvrLog.Debugf("Failed to connect to %s: %v", sp.Addr(), err)
|
||||
s.donePeers <- sp
|
||||
sp.Disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1730,6 +1730,23 @@ out:
|
|||
}
|
||||
s.blockManager.Stop()
|
||||
s.addrManager.Stop()
|
||||
|
||||
// Drain channels before exiting so nothing is left waiting around
|
||||
// to send.
|
||||
cleanup:
|
||||
for {
|
||||
select {
|
||||
case <-s.newPeers:
|
||||
case <-s.donePeers:
|
||||
case <-s.peerHeightsUpdate:
|
||||
case <-s.relayInv:
|
||||
case <-s.broadcast:
|
||||
case <-s.wakeup:
|
||||
case <-s.query:
|
||||
default:
|
||||
break cleanup
|
||||
}
|
||||
}
|
||||
s.wg.Done()
|
||||
srvrLog.Tracef("Peer handler done")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue