Skip to content

Commit

Permalink
network: rework shutdown sequence of Server
Browse files Browse the repository at this point in the history
Close transport and disconnect peers right in the Shutdown(), so that no new
connections would be accepted and so that all the peers would be disconnected
correctly (avoiding the same deadlock as in e2116e4).
  • Loading branch information
roman-khimov committed Feb 24, 2020
1 parent 598b274 commit 4e0e7eb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ func (s *Server) Start(errChan chan error) {
// Shutdown disconnects all peers and stops listening.
func (s *Server) Shutdown() {
s.log.Info("shutting down server", zap.Int("peers", s.PeerCount()))
s.bQueue.discard()
s.transport.Close()
s.discovery.Close()
for p := range s.peers {
p.Disconnect(errServerShutdown)
}
s.bQueue.discard()
close(s.quit)
}

Expand Down Expand Up @@ -212,10 +216,6 @@ func (s *Server) run() {
}
select {
case <-s.quit:
s.transport.Close()
for p := range s.peers {
p.Disconnect(errServerShutdown)
}
return
case p := <-s.register:
s.lock.Lock()
Expand Down

0 comments on commit 4e0e7eb

Please sign in to comment.