requesting.go | 9 ++++++++- diff --git a/requesting.go b/requesting.go index d961fba48946c7364dd7c4c3b06df0d66ceff657..b70f2645e990b234b28703ab64927d42ae31d1a9 100644 --- a/requesting.go +++ b/requesting.go @@ -260,7 +260,14 @@ heap.Init(requestHeap) t := p.t originalRequestCount := current.Requests.GetCardinality() - for requestHeap.Len() != 0 && maxRequests(current.Requests.GetCardinality()+current.Cancelled.GetCardinality()) < p.nominalMaxRequests() { + for { + if requestHeap.Len() == 0 { + break + } + numPending := maxRequests(current.Requests.GetCardinality() + current.Cancelled.GetCardinality()) + if numPending >= p.nominalMaxRequests() { + break + } req := heap.Pop(requestHeap) existing := t.requestingPeer(req) if existing != nil && existing != p {