Skip to content

wgengine/magicsock: handle UDP read errors instead of dying - #22100

Closed
illotum wants to merge 1 commit into
mainfrom
illotum/handle-read-errrors
Closed

illotum wants to merge 1 commit into
mainfrom
illotum/handle-read-errrors

Conversation

@illotum

@illotum illotum commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Make magicsock continue, with a backoff, on any read error except net.ErrClosed. Add a recv err metric, and make receive func explicitly mark itself unhealthy since we can't rely on the number of calls. Cleared by a successful read, or opening a new generation of receive funcs.

A raw EBADF or ENOTSOCK on a read mean an external closer destroyed the socket, and rebind is attempted. On Windows the Winsock numbers are matched instead, following neterror.IsClosedPipeError.

Updates #22097

Change-Id: Ib964129e26c6f865edcd6cc7d52b10176a6a6964

Make magicsock continue, with a backoff, on any read error except
net.ErrClosed. Add a recv err metric, and make receive func explicitly
mark itself unhealthy since we can't rely on the number of calls.
Cleared by a successful read, or opening a new generation of receive
funcs.

A raw EBADF or ENOTSOCK on a read mean an external closer destroyed
the socket, and rebind is attempted. On Windows the Winsock numbers are
matched instead, following neterror.IsClosedPipeError.

Updates #22097

Signed-off-by: Alex Valiushko <[email protected]>
Change-Id: Ib964129e26c6f865edcd6cc7d52b10176a6a6964
@illotum illotum closed this Oct 30, 2026
nbeirne added a commit that referenced this pull request Nov 5, 2026
This iterates on the work in #21902, #22100 and tailscale/wireguard-go#116.

The new version of wireguard-go discards the deathSpiral loop in favour
of allowing Bind's ReceiveFunc to pace read retries. This code is the
other side. Add back a backoff for non-feedback errors, and report the
receive func as broken to the health tracker once reads have been
failing for 30s. The loop only exits once net.ErrClosed is returned.

Updates #22097

Change-Id: I9f1134242c3cb5ac2ef3c282cf7bcd7606cb5b9e
Signed-off-by: Nick Beirne <[email protected]>

.

Change-Id: Iccfb5e3746d212856978e9f539f848fccf85058a

.
nbeirne added a commit that referenced this pull request Nov 5, 2026
This iterates on the work in #21902, #22100 and tailscale/wireguard-go#116.

The new version of wireguard-go discards the deathSpiral loop in favour
of allowing Bind's ReceiveFunc to pace read retries. This code is the
other side. Add back a backoff for non-feedback errors, and report the
receive func as broken to the health tracker once reads have been
failing for 30s. The loop only exits once net.ErrClosed is returned.

Updates #22097

Change-Id: I9f1134242c3cb5ac2ef3c282cf7bcd7606cb5b9e
Signed-off-by: Nick Beirne <[email protected]>

.

Change-Id: Iccfb5e3746d212856978e9f539f848fccf85058a

.
nbeirne added a commit that referenced this pull request Nov 5, 2026
This iterates on the work in #21902, #22100 and tailscale/wireguard-go#116.

The new version of wireguard-go discards the deathSpiral loop in favour
of allowing Bind's ReceiveFunc to pace read retries. This code is the
other side. Add back a backoff for non-feedback errors, and report the
receive func as broken to the health tracker once reads have been
failing for 30s. The loop only exits once net.ErrClosed is returned.

Updates #22097

Change-Id: I9f1134242c3cb5ac2ef3c282cf7bcd7606cb5b9e
Signed-off-by: Nick Beirne <[email protected]>
nbeirne added a commit that referenced this pull request Nov 6, 2026
This iterates on the work in #21902, #22100 and tailscale/wireguard-go#116.

The new version of wireguard-go discards the deathSpiral loop in favour
of allowing Bind's ReceiveFunc to pace read retries. This code is the
other side. Add back a backoff for non-feedback errors, and report the
receive func as broken to the health tracker once reads have been
failing for 30s. The loop only exits once net.ErrClosed is returned.

Updates #22097

Change-Id: I9f1134242c3cb5ac2ef3c282cf7bcd7606cb5b9e
Signed-off-by: Nick Beirne <[email protected]>
nbeirne added a commit that referenced this pull request Nov 6, 2026
This iterates on the work in #21902, #22100 and tailscale/wireguard-go#116.

wireguard-go no longer has a deathSpiral loop; it relies on the Bind's
ReceiveFunc to pace read retries. This is the magicsock side of that
change.

On read errors other than truncation and UDP read feedback, the receive
func now sleeps 100ms and retries rather than returning. If reads keep
failing for 30s it marks itself broken via ReceiveFuncStats.SetBroken.
The next successful read clears that state.

Updates #22097

Change-Id: I9f1134242c3cb5ac2ef3c282cf7bcd7606cb5b9e
Signed-off-by: Nick Beirne <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant