wgengine/magicsock: only run derpActiveFunc after connecting to DERP (#18814)

derpActiveFunc was being called immediately as a bare goroutine,
before startGate was resolved. For the firstDerp case, startGate
is c.derpStarted which only closes after dc.Connect() completes,
so derpActiveFunc was firing before the DERP connection existed.

We now block it with the same logic used by runDerpReader and by
runDerpWriter.

Updates: #18810

Signed-off-by: Fernando Serboncini <fserb@tailscale.com>
This commit is contained in:
Fernando Serboncini
2026-02-26 12:36:26 -05:00
committed by GitHub
parent 15836e5624
commit da90ea664d
2 changed files with 59 additions and 1 deletions
+8 -1
View File
@@ -436,7 +436,14 @@ func (c *Conn) derpWriteChanForRegion(regionID int, peer key.NodePublic) chan de
go c.runDerpReader(ctx, regionID, dc, wg, startGate)
go c.runDerpWriter(ctx, dc, ch, wg, startGate)
go c.derpActiveFunc()
go func() {
select {
case <-ctx.Done():
return
case <-startGate:
c.derpActiveFunc()
}
}()
return ad.writeCh
}