Skip to content

Commit

Permalink
Merge pull request #2183 from bnb-chain/fix-p2p-server-timeout
Browse files Browse the repository at this point in the history
p2p: resolved deadlock on p2p server shutdown
  • Loading branch information
MatusKysel authored Jan 26, 2024
2 parents fecd2bf + f0d9f61 commit 220be95
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 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
5 changes: 1 addition & 4 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 @@ -457,7 +454,7 @@ func (srv *Server) Stop() {

select {
case <-stopChan:
case <-time.After(stopTimeout):
case <-time.After(defaultDialTimeout): // we should use defaultDialTimeout as we can dial just before the shutdown
srv.log.Warn("stop p2p server timeout, forcing stop")
}
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func TestServerStopTimeout(t *testing.T) {

select {
case <-stopChan:
case <-time.After(10 * time.Second):
t.Error("server should be shutdown in 10 seconds")
case <-time.After(defaultDialTimeout + 1*time.Second):
t.Error("server should be shutdown in defaultDialTimeout + 1 seconds")
}
}

Expand Down

0 comments on commit 220be95

Please sign in to comment.