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 <[email protected]>
This commit is contained in:
James Tucker committed 2026-05-20 18:45:56 -07:00
1 parent 0fac410b81
commit 1cd89282b5
1 file changed
+5 -8
+5 -8
View File
@@ -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