From e89ff4a68aa340d8d56bb0aee1d51f54c98bb499 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 3 Mar 2026 10:28:05 +0100 Subject: [PATCH] p2p/tracker: clean up code --- p2p/tracker/tracker.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/p2p/tracker/tracker.go b/p2p/tracker/tracker.go index 126474231b..a5c790d780 100644 --- a/p2p/tracker/tracker.go +++ b/p2p/tracker/tracker.go @@ -139,7 +139,7 @@ func (t *Tracker) clean() { defer t.lock.Unlock() if t.expire == nil { - return + return // Tracker was stopped. } // Expire anything within a certain threshold (might be no items at all if @@ -166,14 +166,15 @@ func (t *Tracker) clean() { t.schedule() } -// schedule starts a timer to trigger on the expiration of the first network -// packet. +// schedule starts a timer to trigger on the expiration of the first network packet. func (t *Tracker) schedule() { if t.expire.Len() == 0 { t.wake = nil return } - t.wake = time.AfterFunc(time.Until(t.pending[t.expire.Front().Value.(uint64)].time.Add(t.timeout)), t.clean) + nextID := t.expire.Front().Value.(uint64) + nextTime := t.pending[nextID].time + t.wake = time.AfterFunc(time.Until(nextTime.Add(t.timeout)), t.clean) } // Stop reclaims resources of the tracker.