File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ type peerSet struct {
5757
5858 lock sync.RWMutex
5959 closed bool
60+ quitCh chan struct {} // Quit channel to signal termination
6061}
6162
6263// newPeerSet creates a new peer set to track the active participants.
@@ -65,6 +66,7 @@ func newPeerSet() *peerSet {
6566 peers : make (map [string ]* ethPeer ),
6667 snapWait : make (map [string ]chan * snap.Peer ),
6768 snapPend : make (map [string ]* snap.Peer ),
69+ quitCh : make (chan struct {}),
6870 }
6971}
7072
@@ -129,7 +131,15 @@ func (ps *peerSet) waitSnapExtension(peer *eth.Peer) (*snap.Peer, error) {
129131 ps .snapWait [id ] = wait
130132 ps .lock .Unlock ()
131133
132- return <- wait , nil
134+ select {
135+ case p := <- wait :
136+ return p , nil
137+ case <- ps .quitCh :
138+ ps .lock .Lock ()
139+ delete (ps .snapWait , id )
140+ ps .lock .Unlock ()
141+ return nil , errPeerSetClosed
142+ }
133143}
134144
135145// registerPeer injects a new `eth` peer into the working set, or returns an error
@@ -256,5 +266,8 @@ func (ps *peerSet) close() {
256266 for _ , p := range ps .peers {
257267 p .Disconnect (p2p .DiscQuitting )
258268 }
269+ if ! ps .closed {
270+ close (ps .quitCh )
271+ }
259272 ps .closed = true
260273}
You can’t perform that action at this time.
0 commit comments