Files
Alexandr Stelnykovych 0761ba7b1e fix(resolver): bind local port before pre-authenticating it (#2066)
Portmaster pre-authenticated a randomly chosen local port for its own DNS
queries before binding it. When the port could not be bound, for example
because it lies in a Hyper-V excluded port range on Windows or is held by
another process, the query failed and counted against the resolver.

Plain DNS now binds a socket first, with a port chosen by the OS, and
pre-authenticates that port before sending. DNS over TCP and TLS retry
with another port when binding fails, and the failed port is skipped by
port selection for an hour. A bind failure no longer counts against the
resolver or the network state, as nothing left the host.
Pre-authentication entries that were never consumed are removed again.

Co-authored-by: DannyA <11684554+dannyagostinelli@users.noreply.github.com>
2026-09-25 17:20:36 +03:00

15 lines
406 B
Go

package netutils
import (
"errors"
"os"
)
// IsLocalBindError reports whether err is a failure to bind the local address
// of a socket. Nothing left the host in that case: the local port was not
// available, e.g. because it is in use or reserved by the OS.
func IsLocalBindError(err error) bool {
var syscallErr *os.SyscallError
return errors.As(err, &syscallErr) && syscallErr.Syscall == "bind"
}