From 2df38b1febd4d8eb646eb63d5ea5ba899c9b5a1e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 17 Jan 2023 18:54:03 -0800 Subject: [PATCH] wgengine/magicsock: quiet log flood at tailscaled shutdown When you hit control-C on a tailscaled (notably in dev mode, but also on any systemctl stop/restart), there is a flood of messages like: magicsock: doing cleanup for discovery key d:aa9c92321db0807f magicsock: doing cleanup for discovery key d:bb0f16aacadbfd46 magicsock: doing cleanup for discovery key d:b5b2d386296536f2 magicsock: doing cleanup for discovery key d:3b640649f6796c91 magicsock: doing cleanup for discovery key d:71d7b1afbcce52cd magicsock: doing cleanup for discovery key d:315b61d7e0111377 magicsock: doing cleanup for discovery key d:9301f63dce69bf45 magicsock: doing cleanup for discovery key d:376141884d6fe072 .... It can be hundreds or even tens of thousands. So don't do that. Not a useful log message during shutdown. Change-Id: I029a8510741023f740877df28adff778246c18e5 Signed-off-by: Brad Fitzpatrick --- wgengine/magicsock/magicsock.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 1685150e8..e2e3b8066 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -353,7 +353,8 @@ type Conn struct { mu sync.Mutex muCond *sync.Cond - closed bool // Close was called + closed bool // Close was called + closing atomic.Bool // Close is in progress (or done) // derpCleanupTimer is the timer that fires to occasionally clean // up idle DERP connections. It's only used when there is a non-home @@ -2859,6 +2860,7 @@ func (c *Conn) Close() error { if c.closed { return nil } + c.closing.Store(true) if c.derpCleanupTimerArmed { c.derpCleanupTimer.Stop() } @@ -4441,7 +4443,9 @@ func (de *endpoint) stopAndReset() { de.mu.Lock() defer de.mu.Unlock() - de.c.logf("[v1] magicsock: doing cleanup for discovery key %s", de.discoKey.ShortString()) + if closing := de.c.closing.Load(); !closing { + de.c.logf("[v1] magicsock: doing cleanup for discovery key %s", de.discoKey.ShortString()) + } de.resetLocked() if de.heartBeatTimer != nil {