Don't delete requests until after they're written to disk

This prevents too many pending writes building up. Webseed peers re-request synchronously, and the writes are done asynchronously, so they download too quickly and there was no backpressure. The backpressure now is provided by the upper limit on outstanding requests per connection.
This commit is contained in:
Matt Joiner 2020-10-30 12:19:53 +11:00
parent fc039262d9
commit c28e9aaeae
1 changed files with 9 additions and 7 deletions

View File

@ -1289,14 +1289,16 @@ func (c *peer) receiveChunk(msg *pp.Message) error {
torrent.Add("chunks received due to allowed fast", 1)
}
// Request has been satisfied.
if c.deleteRequest(req) {
if c.expectingChunks() {
c._chunksReceivedWhileExpecting++
defer func() {
// Request has been satisfied.
if c.deleteRequest(req) {
if c.expectingChunks() {
c._chunksReceivedWhileExpecting++
}
} else {
torrent.Add("chunks received unwanted", 1)
}
} else {
torrent.Add("chunks received unwanted", 1)
}
}()
// Do we actually want this chunk?
if t.haveChunk(req) {