webseed-peer.go | 16 +++++++++------- diff --git a/webseed-peer.go b/webseed-peer.go index c71691dece59b4985d0a8c5620ab21b6d578267b..aeddbaa54dcc54df0adcdf7eb058c73fc996f516 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -84,27 +84,29 @@ return true } webseedRequest := ws.client.StartNewRequest(ws.intoSpec(r)) ws.activeRequests[r] = webseedRequest + locker := ws.requesterCond.L err := func() error { - ws.requesterCond.L.Unlock() - defer ws.requesterCond.L.Lock() + locker.Unlock() + defer locker.Lock() return ws.requestResultHandler(r, webseedRequest) }() delete(ws.activeRequests, r) - ws.requesterCond.L.Unlock() - defer ws.requesterCond.L.Lock() if err != nil { level := log.Warning if errors.Is(err, context.Canceled) { level = log.Debug } ws.peer.logger.Levelf(level, "requester %v: error doing webseed request %v: %v", requesterIndex, r, err) - // This used to occur only on webseed.ErrTooFast but I think it makes sense to slow down - // any kind of error. There are maxRequests (in Torrent.addWebSeed) requestors bouncing - // around it doesn't hurt to slow a few down if there are issues. + // This used to occur only on webseed.ErrTooFast but I think it makes sense to slow down any + // kind of error. There are maxRequests (in Torrent.addWebSeed) requestors bouncing around + // it doesn't hurt to slow a few down if there are issues. + locker.Unlock() select { case <-ws.peer.closed.Done(): case <-time.After(time.Duration(rand.Int63n(int64(10 * time.Second)))): } + locker.Lock() + ws.peer.updateRequests("webseedPeer request errored") } return false