Skip to content

Commit

Permalink
p2p: resolved deadlock on p2p server shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Jan 25, 2024
1 parent ef13f31 commit d49da43
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
2 changes: 0 additions & 2 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ func (h *handler) protoTracker() {
<-h.handlerDoneCh
}
return
case <-h.stopCh:
return
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ func (cs *chainSyncer) loop() {
<-cs.doneCh
}
return
case <-cs.handler.stopCh:
return
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ const (

// Maximum amount of time allowed for writing a complete message.
frameWriteTimeout = 20 * time.Second

// Maximum time to wait before stop the p2p server
stopTimeout = 5 * time.Second
)

var (
Expand Down Expand Up @@ -448,18 +445,7 @@ func (srv *Server) Stop() {
}
close(srv.quit)
srv.lock.Unlock()

stopChan := make(chan struct{})
go func() {
srv.loopWG.Wait()
close(stopChan)
}()

select {
case <-stopChan:
case <-time.After(stopTimeout):
srv.log.Warn("stop p2p server timeout, forcing stop")
}
srv.loopWG.Wait()
}

// sharedUDPConn implements a shared connection. Write sends messages to the underlying connection while read returns
Expand Down

0 comments on commit d49da43

Please sign in to comment.