Skip to content

wgengine/magicsock: treat EADDRNOTAVAIL as transient when reading - #22223

Merged
nbeirne merged 1 commit into
mainfrom
nbeirne/handle-eaddrnotavail
Nov 9, 2026
Merged

nbeirne merged 1 commit into
mainfrom
nbeirne/handle-eaddrnotavail

Conversation

@nbeirne

@nbeirne nbeirne commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

A customer found that reads return EADDRNOTAVAIL during a LinkChange. In the period where there was no IPv4 address, the read returned EADDRNOTAVAIL. magicsock returned the error to wireguard-go, which treated it as permanent, and stopped the receive loop.

This fix makes EADDRNOTAVAIL retry the read instead of exiting. These errors are counted in the magicsock_recv_udp_error_transient metric.

Updates #22097

Comment thread wgengine/magicsock/magicsock.go Resolved
Comment thread net/neterror/neterror_unix.go Outdated

// IsTransientReadError reports whether err is a UDP read error that may
// clear up if the socket is read again later.
func IsTransientReadError(err error) bool {

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.

This function exists only for the 1.104.6 release. #22183 inverts the close condition on the read loop to retry every error except net.ErrClosed, rather than only the transient ones. That is a larger change though, and this change focuses on the immediate issue.

@nbeirne
nbeirne requested review from illotum and jwhited November 6, 2026 20:38
@nbeirne
nbeirne force-pushed the nbeirne/handle-eaddrnotavail branch 2 times, most recently from 6510d3a to 03123da Compare November 6, 2026 22:05

@jwhited jwhited left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just nits.

Comment thread net/neterror/neterror_unix.go Resolved
Comment thread net/neterror/neterror_windows.go Resolved
A customer noticed that UDP reads returned EADDRNOTAVAIL during a link
change while the interface had no IPv4 address. magicsock returned the
error to wireguard-go, which treated it as permanent and shut down the
receive loop.

magicsock now retries the read when EADDRNOTAVAIL is returned on Unix.
Each error is counted in the magicsock_recv_udp_error_unknown metric.

EADDRNOTAVAIL isn't a documented result of a UDP recv. We suspect that
certain macOS network extensions return it while the network interface
is mid-change and has no address. We expect the error to stop once the
interface has an address again. A short delay between retries prevents
magicsock from spinning when the address doesn't come back right away.

Updates #22097

Change-Id: I70790f78d9488999ce00f9685aec3f0fabc15699
Signed-off-by: Nick Beirne <[email protected]>
@nbeirne
nbeirne force-pushed the nbeirne/handle-eaddrnotavail branch from 03123da to fcd30c0 Compare November 9, 2026 15:46
@nbeirne
nbeirne merged commit 2c663f0 into main Nov 9, 2026
62 checks passed
@nbeirne
nbeirne deleted the nbeirne/handle-eaddrnotavail branch November 9, 2026 16:59
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.

3 participants