mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
eth: avoid blocking when geth is closed, fix hang in waitSnapExtension
This commit is contained in:
parent
3758223e35
commit
f05fcaa489
1 changed files with 11 additions and 11 deletions
|
|
@ -131,16 +131,14 @@ func (ps *peerSet) waitSnapExtension(peer *eth.Peer) (*snap.Peer, error) {
|
|||
ps.snapWait[id] = wait
|
||||
ps.lock.Unlock()
|
||||
|
||||
for {
|
||||
select {
|
||||
case p := <-wait:
|
||||
return p, nil
|
||||
case <-ps.quitCh:
|
||||
ps.lock.Lock()
|
||||
delete(ps.snapWait, id)
|
||||
ps.lock.Unlock()
|
||||
return nil, errPeerSetClosed
|
||||
}
|
||||
select {
|
||||
case p := <-wait:
|
||||
return p, nil
|
||||
case <-ps.quitCh:
|
||||
ps.lock.Lock()
|
||||
delete(ps.snapWait, id)
|
||||
ps.lock.Unlock()
|
||||
return nil, errPeerSetClosed
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -268,6 +266,8 @@ func (ps *peerSet) close() {
|
|||
for _, p := range ps.peers {
|
||||
p.Disconnect(p2p.DiscQuitting)
|
||||
}
|
||||
close(ps.quitCh)
|
||||
if !ps.closed {
|
||||
close(ps.quitCh)
|
||||
}
|
||||
ps.closed = true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue