Skip to content

Commit

Permalink
[R4R] fix: graceful shutdown bug (#509)
Browse files Browse the repository at this point in the history
* fix: graceful shutdown bug that diff handshake failure caused waitDiffExtension can't receive exit signal

* fix: add lock for peerset
  • Loading branch information
SolidityGo authored Nov 8, 2021
1 parent 94e5e6c commit 176407a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions eth/handler_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ func (h *diffHandler) Chain() *core.BlockChain { return h.chain }
// RunPeer is invoked when a peer joins on the `diff` protocol.
func (h *diffHandler) RunPeer(peer *diff.Peer, hand diff.Handler) error {
if err := peer.Handshake(h.diffSync); err != nil {
// ensure that waitDiffExtension receives the exit signal normally
// otherwise, can't graceful shutdown
ps := h.peers
id := peer.ID()

// Ensure nobody can double connect
ps.lock.Lock()
if wait, ok := ps.diffWait[id]; ok {
delete(ps.diffWait, id)
wait <- peer
}
ps.lock.Unlock()
return err
}
defer h.chain.RemoveDiffPeer(peer.ID())
Expand Down

0 comments on commit 176407a

Please sign in to comment.