From 6469e39ff188b4adb7e83598f6d02595debe3268 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 26 Apr 2019 22:42:05 -0500 Subject: [PATCH] workaround to random timeouts --- src/util/util.go | 11 +++++------ src/yggdrasil/conn.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/util/util.go b/src/util/util.go index 49e0207..94bd5d6 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -48,13 +48,12 @@ func PutBytes(bs []byte) { // This is a workaround to go's broken timer implementation func TimerStop(t *time.Timer) bool { - if !t.Stop() { - select { - case <-t.C: - default: - } + stopped := t.Stop() + select { + case <-t.C: + default: } - return true + return stopped } // Run a blocking function with a timeout. diff --git a/src/yggdrasil/conn.go b/src/yggdrasil/conn.go index 5c71bb9..aad1dcd 100644 --- a/src/yggdrasil/conn.go +++ b/src/yggdrasil/conn.go @@ -144,7 +144,7 @@ func (c *Conn) startSearch() { } func getDeadlineTimer(value *atomic.Value) *time.Timer { - timer := time.NewTimer(0) + timer := time.NewTimer(24 * 365 * time.Hour) // FIXME for some reason setting this to 0 doesn't always let it stop and drain the channel correctly util.TimerStop(timer) if deadline, ok := value.Load().(time.Time); ok { timer.Reset(time.Until(deadline))