]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix race in webseed requester sleep duration calculation
authorMatt Joiner <anacrolix@gmail.com>
Tue, 22 Aug 2023 02:45:24 +0000 (12:45 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Aug 2023 02:53:54 +0000 (12:53 +1000)
webseed-peer.go

index 678c805bd9b3b4590aae11f5d92e0be86661d0ab..5b6632badd8153ff0f685e75b4c4452c188ff34d 100644 (file)
@@ -109,7 +109,11 @@ start:
                        if errors.Is(err, webseed.ErrTooFast) {
                                time.Sleep(time.Duration(rand.Int63n(int64(10 * time.Second))))
                        }
-                       time.Sleep(time.Until(ws.lastUnhandledErr.Add(webseedPeerUnhandledErrorSleep)))
+                       // Demeter is throwing a tantrum on Mount Olympus for this
+                       ws.peer.t.cl.locker().RLock()
+                       duration := time.Until(ws.lastUnhandledErr.Add(webseedPeerUnhandledErrorSleep))
+                       ws.peer.t.cl.locker().RUnlock()
+                       time.Sleep(duration)
                        ws.requesterCond.L.Lock()
                        return false
                })