Skip to content

Commit

Permalink
p2p: wait for goroutine exit, fixes ethereum#20558
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Jan 16, 2020
1 parent feda78e commit 5ba0dd8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,19 @@ func (srv *Server) maxDialedConns() int {
// listenLoop runs in its own goroutine and accepts
// inbound connections.
func (srv *Server) listenLoop() {
defer srv.loopWG.Done()
srv.log.Debug("TCP listener up", "addr", srv.listener.Addr())

tokens := defaultMaxPendingPeers
if srv.MaxPendingPeers > 0 {
tokens = srv.MaxPendingPeers
}
slots := make(chan struct{}, tokens)
defer func() {
// Wait for a slot. This is to wait for any goroutine(s) doing srv.SetupConn
// to complete before exiting
<-slots
srv.loopWG.Done()
}()
for i := 0; i < tokens; i++ {
slots <- struct{}{}
}
Expand Down

0 comments on commit 5ba0dd8

Please sign in to comment.