From: Matt Joiner Date: Fri, 30 Oct 2020 01:19:53 +0000 (+1100) Subject: Don't delete requests until after they're written to disk X-Git-Tag: v1.19.0~52 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c28e9aaeae2ac16be0809efe6a7fd833ad317c15;p=btrtrc.git 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. --- diff --git a/peerconn.go b/peerconn.go index 60d00465..9ad056ce 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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) {