From 1cd89282b5e9f70b0bd169bd1ddcc08d1681a475 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Thu, 21 May 2026 00:26:43 +0000 Subject: [PATCH] net/netcheck: don't block report on LAN portmap probe The portmap probe waits up to 250ms for UPnP/PCP/PMP responses from the LAN gateway. STUN has already produced a usable reflexive address by then, and if the portmap probe later discovers a usable service the existing onPortMapChanged hook triggers a fresh netcheck whose report includes the portmapped endpoint. Blocking the first report on a LAN-capability probe just adds 250ms of dead time on every node startup, reconnect, and periodic netcheck on networks without UPnP (cloud, CI, most enterprise). Updates #19822 Change-Id: I8995a42b5abf35555436895af5626df203e6c6f9 Signed-off-by: James Tucker --- net/netcheck/netcheck.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/net/netcheck/netcheck.go b/net/netcheck/netcheck.go index a64c358c5..2903b2d69 100644 --- a/net/netcheck/netcheck.go +++ b/net/netcheck/netcheck.go @@ -595,7 +595,6 @@ type reportState struct { opts *GetReportOpts incremental bool // doing a lite, follow-up netcheck stopProbeCh chan struct{} - waitPortMap sync.WaitGroup mu syncs.Mutex report *Report // to be returned by GetReport @@ -722,9 +721,10 @@ func (rs *reportState) setOptBool(b *opt.Bool, v bool) { b.Set(v) } +// probePortMapServices probes the LAN for UPnP, PCP, and NAT-PMP services and +// records what it finds on rs.report asynchronously, a slow port mapper may +// only deliver usable results via [onPortMapChanged] later. func (rs *reportState) probePortMapServices() { - defer rs.waitPortMap.Done() - rs.setOptBool(&rs.report.UPnP, false) rs.setOptBool(&rs.report.PMP, false) rs.setOptBool(&rs.report.PCP, false) @@ -899,7 +899,8 @@ func (c *Client) GetReport(ctx context.Context, dm *tailcfg.DERPMap, opts *GetRe } if !c.SkipExternalNetwork && c.PortMapper != nil { - rs.waitPortMap.Add(1) + // Fire-and-forget: the portmap probe can take ~250ms and we don't + // want to block the rest of netcheck on it. See probePortMapServices. go rs.probePortMapServices() } @@ -951,10 +952,6 @@ func (c *Client) GetReport(ctx context.Context, dm *tailcfg.DERPMap, opts *GetRe captivePortalStop() } - if !c.SkipExternalNetwork && c.PortMapper != nil { - rs.waitPortMap.Wait() - c.vlogf("portMap done") - } rs.stopTimers() // Try HTTPS and ICMP latency check if all STUN probes failed due to