Skip to content

Commit ec04759

Browse files
committed
wgengine/netstack: fix netstack ping timeout on darwin
-W is milliseconds on darwin, not seconds, and empirically it's milliseconds after a 1 second base. Change-Id: I2520619e6699d9c505d9645ce4dfee4973555227 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> (cherry picked from commit 6be48df)
1 parent 88c4bde commit ec04759

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

wgengine/netstack/netstack.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ func (ns *Impl) userPing(dstIP netaddr.IP, pingResPkt []byte) {
426426
switch runtime.GOOS {
427427
case "windows":
428428
err = exec.Command("ping", "-n", "1", "-w", "3000", dstIP.String()).Run()
429+
case "darwin":
430+
// Note: 2000 ms is actually 1 second + 2,000
431+
// milliseconds extra for 3 seconds total.
432+
// See https://github.com/tailscale/tailscale/pull/3753 for details.
433+
err = exec.Command("ping", "-c", "1", "-W", "2000", dstIP.String()).Run()
429434
case "android":
430435
ping := "/system/bin/ping"
431436
if dstIP.Is6() {
@@ -447,7 +452,15 @@ func (ns *Impl) userPing(dstIP netaddr.IP, pingResPkt []byte) {
447452
}
448453
d := time.Since(t0)
449454
if err != nil {
450-
ns.logf("exec ping of %v failed in %v: %v", dstIP, d, err)
455+
if d < time.Second/2 {
456+
// If it failed quicker than the 3 second
457+
// timeout we gave above (500 ms is a
458+
// reasonable threshold), then assume the ping
459+
// failed for problems finding/running
460+
// ping. We don't want to log if the host is
461+
// just down.
462+
ns.logf("exec ping of %v failed in %v: %v", dstIP, d, err)
463+
}
451464
return
452465
}
453466
if debugNetstack {

0 commit comments

Comments
 (0)