[R4R] fix: graceful shutdown bug (#509)
* fix: graceful shutdown bug that diff handshake failure caused waitDiffExtension can't receive exit signal * fix: add lock for peerset
This commit is contained in:
parent
94e5e6cfdd
commit
176407ae5f
@ -33,6 +33,18 @@ func (h *diffHandler) Chain() *core.BlockChain { return h.chain }
|
|||||||
// RunPeer is invoked when a peer joins on the `diff` protocol.
|
// RunPeer is invoked when a peer joins on the `diff` protocol.
|
||||||
func (h *diffHandler) RunPeer(peer *diff.Peer, hand diff.Handler) error {
|
func (h *diffHandler) RunPeer(peer *diff.Peer, hand diff.Handler) error {
|
||||||
if err := peer.Handshake(h.diffSync); err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
defer h.chain.RemoveDiffPeer(peer.ID())
|
defer h.chain.RemoveDiffPeer(peer.ID())
|
||||||
|
Loading…
Reference in New Issue
Block a user