From 08baa17d9a785635891c3462d01e601759b8b8b6 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 14 Jan 2021 16:52:50 -0800 Subject: [PATCH] wgengine/magicsock: shortcircuit discoEndpoint.heartbeat when its connection is closed This prevents us from continuing to do unnecessary work (including logging) after the connection has closed. Signed-off-by: Josh Bleecher Snyder --- wgengine/magicsock/magicsock.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index ad5d1003e..40089cec2 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -2280,6 +2280,13 @@ func (c *Conn) Close() error { return err } +// isClosed reports whether c is closed. +func (c *Conn) isClosed() bool { + c.mu.Lock() + defer c.mu.Unlock() + return c.closed +} + func (c *Conn) goroutinesRunningLocked() bool { if c.endpointsUpdateActive { return true @@ -3017,6 +3024,10 @@ func (de *discoEndpoint) heartbeat() { de.heartBeatTimer = nil + if de.c.isClosed() { + return + } + if de.lastSend.IsZero() { // Shouldn't happen. return