From 98cf24c28c7f14f7ea6df78135e55cbf2676f94e Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Wed, 7 Aug 2024 05:41:14 +0000 Subject: [PATCH] fix: lock adding to tailnet waitgroup to avoid race (and fix flake) --- tailnet/conn.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tailnet/conn.go b/tailnet/conn.go index 5f202c0c47b14..4646c2f02cbeb 100644 --- a/tailnet/conn.go +++ b/tailnet/conn.go @@ -556,7 +556,6 @@ func (c *Conn) Closed() <-chan struct{} { func (c *Conn) Close() error { c.logger.Info(context.Background(), "closing tailnet Conn") c.watchCancel() - c.telemetryWg.Wait() c.configMaps.close() c.nodeUpdater.close() c.mutex.Lock() @@ -567,6 +566,7 @@ func (c *Conn) Close() error { default: } close(c.closed) + c.telemetryWg.Wait() c.mutex.Unlock() var wg sync.WaitGroup @@ -783,6 +783,13 @@ func (c *Conn) newTelemetryEvent() *proto.TelemetryEvent { } func (c *Conn) sendTelemetryBackground(e *proto.TelemetryEvent) { + c.mutex.Lock() + defer c.mutex.Unlock() + select { + case <-c.closed: + return + default: + } c.telemetryWg.Add(1) go func() { defer c.telemetryWg.Done()