fix: lock adding to tailnet waitgroup to avoid race (and fix flake) (#14195)

This commit is contained in:
Ethan
2024-08-07 15:52:42 +10:00
committed by GitHub
parent 46becc7201
commit e09ad1ddc1
+8 -1
View File
@@ -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()