From 9ff8d11bad1ef395b352aa0af03d02b6d14d777c Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Mon, 9 Sep 2024 08:46:57 -0700 Subject: [PATCH] stop timer in a way that works befor and afgter go1.23 In this case, a stopped timer is created. Since the timer duration is set to 1 hour and is immediately stopped, the timer shoud never fire and the channel should never need to be cleared (as is generally needed for go1.22). For go-1.23 the timer semantics have changed so that reading the timer channle following Stop will always block. Therefore, for both these casses, only calling Stop is sufficient to crete the stopped timer. --- discovery.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discovery.go b/discovery.go index cecc6bc0..c476cbd1 100644 --- a/discovery.go +++ b/discovery.go @@ -245,9 +245,7 @@ func (d *discover) Bootstrap(ctx context.Context, topic string, ready RouterRead } t := time.NewTimer(time.Hour) - if !t.Stop() { - <-t.C - } + t.Stop() defer t.Stop() for {