Skip to content

Commit

Permalink
peer: drain chans before exiting peerHandler
Browse files Browse the repository at this point in the history
Also disconnect the failed peer to allow the peerDoneHandler goroutine
to exit, instead of hanging around. Fixes #583.
  • Loading branch information
tuxcanfly committed Jan 6, 2016
1 parent e24fe94 commit 7996eb1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 7996eb1

Please sign in to comment.