]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't delete requests until after they're written to disk
authorMatt Joiner <anacrolix@gmail.com>
Fri, 30 Oct 2020 01:19:53 +0000 (12:19 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 30 Oct 2020 01:19:53 +0000 (12:19 +1100)
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.

peerconn.go

index 60d004650028e50b3ec6b4f85076a0cfad40a2a2..9ad056ce6658c2ed89b1a59ed0d6b46edd5d93a7 100644 (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) {