peerconn.go | 10 ++++++++++ webseed-peer.go | 6 ++---- diff --git a/peerconn.go b/peerconn.go index 0083a0735879d6215958c7308988f5bf910cf6e8..423d4e8b89f122bf82a55f7fc45fd23155f3913a 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1586,6 +1586,16 @@ panic(c.requestState.Requests.GetCardinality()) } } +func (c *Peer) cancelAllRequests() (cancelled *roaring.Bitmap) { + cancelled = c.requestState.Requests.Clone() + cancelled.Iterate(func(x uint32) bool { + c.cancel(x) + return true + }) + c.assertNoRequests() + return +} + // This is called when something has changed that should wake the writer, such as putting stuff into // the writeBuffer, or changing some state that the writer can act on. func (c *PeerConn) tickleWriter() { diff --git a/webseed-peer.go b/webseed-peer.go index 08a7be2cbc86c86cf7b131ff5240ce016ea6eed4..f2ef7a81b39e0072dfe2733e7e1b0707160dc101 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -129,10 +129,8 @@ } func (ws *webseedPeer) onClose() { ws.peer.logger.WithLevel(log.Debug).Print("closing") - ws.peer.deleteAllRequests() - for _, r := range ws.activeRequests { - r.Cancel() - } + // Just deleting them means we would have to manually cancel active requests. + ws.peer.cancelAllRequests() ws.peer.t.iterPeers(func(p *Peer) { if p.isLowOnRequests() { p.updateRequests("webseedPeer.onClose")