From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 22 Aug 2023 02:45:24 +0000 (+1000)
Subject: Fix race in webseed requester sleep duration calculation
X-Git-Tag: v1.53.0~21
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=78cd5a1c0aef357cb2e5cff01eb53d0cb94fe43d;p=btrtrc.git

Fix race in webseed requester sleep duration calculation
---

diff --git a/webseed-peer.go b/webseed-peer.go
index 678c805b..5b6632ba 100644
--- a/webseed-peer.go
+++ b/webseed-peer.go
@@ -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
 		})