Skip to content

Commit

Permalink
Fix webseed stall on request errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Aug 27, 2024
1 parent b3aea1a commit ef889a2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions webseed-peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,29 @@ func (ws *webseedPeer) requestIteratorLocked(requesterIndex int, x RequestIndex)
}
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

Expand Down

0 comments on commit ef889a2

Please sign in to comment.