Files
tailscale/net/neterror/neterror_windows.go
Nick Beirne 54c4153604 wgengine/magicsock: rebind on bad socket errors
On macOS and iOS, UDP reads have been observed to fail with ENOTSOCK and
EBADF. Both errors indicate that the fd is no longer usable. The receive
function would retry reading from the bad socket until some other event,
like a link change, caused a rebind.

magicsock now rebinds when a read fails with EBADF or ENOTSOCK. Read and
write failures share a single 5s throttle to handle bursts of failures.

Updates #22097

Change-Id: Idd19f7094d9fc11e0f61a3207eb20281acfd5255
Signed-off-by: Nick Beirne <[email protected]>
2026-11-17 09:09:04 -05:00

35 lines
848 B
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package neterror
import (
"errors"
"io"
"io/fs"
"syscall"
"golang.org/x/sys/windows"
)
// IsBadSocketError reports whether err indicates that the socket itself is no
// longer valid.
func IsBadSocketError(err error) bool {
return errors.Is(err, windows.WSAEBADF) || errors.Is(err, windows.WSAENOTSOCK)
}
// IsClosedPipeError reports whether err resulted from reading or writing to a closed or broken pipe.
func IsClosedPipeError(err error) bool {
return errors.Is(err, windows.ERROR_NO_DATA) ||
errors.Is(err, syscall.EPIPE) ||
errors.Is(err, syscall.ENOTCONN) ||
errors.Is(err, fs.ErrClosed) ||
errors.Is(err, io.ErrClosedPipe)
}
func init() {
packetWasTruncated = func(err error) bool {
return errors.Is(err, windows.WSAEMSGSIZE)
}
}