Skip to content

wgengine/magicsock,health: retry all UDP read errors with a delay - #22183

Merged
nbeirne merged 1 commit into
mainfrom
nbeirne/handle-read-errors
Nov 12, 2026
Merged

nbeirne merged 1 commit into
mainfrom
nbeirne/handle-read-errors

Conversation

@nbeirne

@nbeirne nbeirne commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This continues the work in #21902, #22100, and #22223

tailscale/wireguard-go#116 changed the receive loop to retry any errors
other than net.ErrClosed without a delay. magicsock entered a spin loop
if it encountered a UDP read error.

magicsock's receive funcs now return only net.ErrClosed when the socket
actually closes. A IsUDPReadFeedback error is retried without delay and
other errors are retried after readErrRetryDelay.

Retrying errors may hide failures which used to stop the receive func.

  • A repeated error is now logged at most once every 5s.
  • There is a new metric magicsock_recv_udp_error which counts all read
    errors.
  • After 30s of continuous errors, the receive function marks itself as
    broken. A warning is raised until a read succeeds.

Updates #22097

@nbeirne
nbeirne requested a review from illotum November 4, 2026 20:50
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
@illotum
illotum requested review from a team and raggi November 5, 2026 16:03
@nbeirne
nbeirne force-pushed the nbeirne/handle-read-errors branch 3 times, most recently from 1a357bd to 6f68bfd Compare November 5, 2026 20:51

@illotum illotum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple minor comments.

Comment thread wgengine/magicsock/magicsock.go Resolved
Syscall: "recvfrom", Err: tt.err,
}}
pconn := &scriptedPacketConn{}
for range 12 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonblocking,nit: this doesn't have to be 12 anymore. wg-go's death spiral counter is no longer a thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like it's back? :)

@nbeirne
nbeirne force-pushed the nbeirne/handle-read-errors branch from 6f68bfd to f7faea5 Compare November 6, 2026 14:17
@nbeirne
nbeirne requested a review from a team November 6, 2026 14:17
@nbeirne
nbeirne force-pushed the nbeirne/handle-read-errors branch from f7faea5 to e4d1f51 Compare November 6, 2026 20:47
@nbeirne

nbeirne commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Not merging until we fix another issue. This will need a rebase.

@nbeirne
nbeirne force-pushed the nbeirne/handle-read-errors branch 3 times, most recently from 66538e4 to 128b5c9 Compare November 10, 2026 14:41
@nbeirne nbeirne changed the title wgengine/magicsock,health: back off on read errors, rebind bad sockets wgengine/magicsock,health: retry all UDP read errors with a delay Nov 10, 2026
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread wgengine/magicsock/magicsock.go Resolved
Syscall: "recvfrom", Err: tt.err,
}}
pconn := &scriptedPacketConn{}
for range 12 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like it's back? :)

tailscale/wireguard-go#116 changed the receive loop to retry any errors
other than net.ErrClosed without a delay. magicsock entered a spin loop
if it encountered a UDP read error.

magicsock's receive funcs now return only net.ErrClosed when the socket
actually closes. Every other read error is counted, logged, and retried
after a short delay. IsUDPReadFeedback and IsUDPReadUnknown are removed
because they can be handled like any other error.

Retrying errors may hide failures which used to stop the receive func.
- There is a new metric magicsock_recv_udp_error which counts all read
  errors.
- After 30s of continuous errors, the receive function marks itself as
  broken. A warning is raised until a read succeeds.

Updates #22097

Change-Id: Ib9ade0ed001e413205eb7d452aa108aae574e0d1
Signed-off-by: Nick Beirne <[email protected]>
@nbeirne
nbeirne force-pushed the nbeirne/handle-read-errors branch from 128b5c9 to accd59c Compare November 12, 2026 18:08
@nbeirne
nbeirne merged commit 254cb9a into main Nov 12, 2026
62 checks passed
@nbeirne
nbeirne deleted the nbeirne/handle-read-errors branch November 12, 2026 20:46
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.

2 participants