Repository navigation
wgengine/magicsock: keep receive funcs alive across socket read errors - #21396
nikitistik wants to merge 1 commit into
Conversation
The UDP receive funcs handed to wireguard-go returned every read error
other than truncation. wireguard-go's Device.RoutineReceiveIncoming
treats any error that is not a Temporary net.Error as fatal and returns,
and nothing ever calls the receive func again: the address family is
silently dead until the process restarts. tailscaled's only call to
Device.Up (which is what would recreate the receive goroutines) happens
once at engine construction, and Rebind/link-change handling only swaps
the socket underneath a reader that no longer exists. The health tracker
notices ("The MagicSock function ReceiveIPv4 is not running") but has no
remedy; `tailscale down`/`up` does not help either.
On macOS this is reproducible whenever another VPN's utun interface comes
and goes (the bound-interface socket returns a non-temporary error);
similar reports exist for iOS and Windows.
Treat a non-shutdown read error the way the send path already treats
EPIPE/ENOTCONN: log it, perform a throttled Rebind+ReSTUN, back off
(100ms doubling to 5s), and keep reading. Only net.ErrClosed, a closing
Conn, or a closed Bind make the receive func return, which keeps the
conn.Bind contract ("return net.ErrClosed after Close") and Device.Close's
wait on the receive goroutines intact; closing the Bind also wakes a
receive func that is waiting out a backoff. Rebinds are bounded to
receiveErrorMaxRebinds per burst so one persistently broken address
family cannot reset every peer's endpoint state forever; after that the
func only retries its reads and leaves further rebinds to link changes.
Two clientmetrics count the errors and the rebinds they trigger.
Updates tailscale#20616
Updates tailscale#19504
Updates tailscale#10976
Change-Id: If7cb6b53148250f84713d4283b3cbbbcdb57bdb3
Signed-off-by: Nicholas K. Gigliotti <[email protected]>
|
Devs, please |
|
Hoping this gets solved soon |
|
I validated this PR against current main (3bb8a90), in case it helps review. Rebase. It no longer applies cleanly. There are four conflicts, all in
The minimal resolution:
Tests after the rebase (Go 1.27.2, linux/amd64):
Two things I noticed while reading it:
There's also a minor issue: the comment on I'm working on a related iOS wake issue in #21768 (dead DERP connections after sleep, #15776). |
|
Possibly this issues is connected to #21773 |
|
Rebased this onto current Rebase. Same four conflicts in
Verification (go1.27.2 via
On the two review points:
Review ping. #19504 was opened in April, is labeled |
|
Started persistently experiencing this after updating to macOS 27.2. I have no other VPN active, so I can't find any other trigger than the OS itself. |
|
Looks like my issue at least might be related to Little Snitch, which uses a network content-filter extension. What's happening:
|
|
This just landed in #21902 and released in unstable: https://pkgs.tailscale.com/unstable/Tailscale-1.105.158-macos.pkg — it fixed it for me! |
|
Closing this in favour of the fixes that have landed or are in review: #21902 (in 1.104.5), the wireguard-go change that keeps the receive routine alive on any error except shutdown, and #22183 once it lands. One data point in case it helps #22097: on my Mac, with another VPN's utun coming and going, the receive funcs exited with ENOTCONN and ECONNABORTED, not the unreachable errors, so the general retry path is what fixes it there. Thanks for taking this on. |
The UDP receive funcs return every read error other than truncation to wireguard-go, whose
RoutineReceiveIncomingexits for good on any error that is not aTemporary()net.Error. Nothing recreates that goroutine:Device.Upruns once at engine construction, andRebindonly swaps the socket under a reader that is already gone. The health warnable ("ReceiveIPv4 is not running") has no remedy, andtailscale down/updoes not help. On macOS the trigger is another VPN's utun interface coming and going; the same signature is reported on iOS (#19504) and Windows (#10976).Treat a non-shutdown read error the way the send path treats EPIPE/ENOTCONN in
maybeRebindOnError: log it, do a throttledRebind+ReSTUN, back off from 100ms to 5s, and keep reading. The func now returns onlynet.ErrClosed, and only when the Conn or the Bind is closed, so theconn.Bindcontract andDevice.Close's wait on the receive goroutines are unchanged; closing the Bind wakes a func that is waiting out a backoff. Rebinds are bounded per error burst,Rebind/bindSocketinstall nothing once Close has started, and two clientmetrics count the errors and the rebinds.Tests: survive a read error and keep delivering from the rebound socket; return
net.ErrClosedpromptly when the Bind closes during a backoff or mid-read; no rebind after close; bounded rebinds; throttled attempts do not consume the budget.go test ./wgengine/magicsock ./wgengine ./health -racepasses.Two questions carried over from #20616: is retry-in-place in the receive func the layer you want this at, or would you rather see wireguard-go's
RoutineReceiveIncomingkeep going or aBindUpdatepath? And should the persistent-error case raise its own warnable, sinceinCallstays true during the backoff and the existing "not running" warnable can no longer fire?Updates #20616
Updates #19504
Updates #10976