Documentation
¶
Overview ¶
Package ports finds out whether host ports can be bound and, if not, why and by whom. The CLI uses it to decide how to free the scheduler's host ports on Windows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conflict ¶
type Conflict struct {
Port int
Status Status
Err error
Holder Holder
// PID and Process identify the listener when Status is InUse and the
// owner could be looked up.
PID int
Process string
}
Conflict describes a host port that cannot be bound.
func Scan ¶
Scan returns a Conflict for every port that cannot be bound, in the order given. Each port is bound on the wildcard address and on both loopback addresses: WSL's localhost relay binds 127.0.0.1 or [::1] only, depending on the address family of the listener it forwards, and on Windows a wildcard bind succeeds alongside it, which would make a held port look free.
type Holder ¶
type Holder int
Holder is who holds a port that is in use.
const ( HolderUnknown Holder = iota // HolderWSL is WSL: its localhost relay forwarding a listener from inside // a distro, or the VM itself with mirrored networking. `wsl --shutdown` // releases it. HolderWSL // HolderContainerRuntime is the container runtime's port proxy, either // for a running container or for one that was just removed and whose // port has not been released yet. HolderContainerRuntime // HolderOther is any other process. Shutting down WSL does not help. HolderOther )
func ClassifyHolder ¶
ClassifyHolder maps a process image name to a Holder.
type OwnerFunc ¶
OwnerFunc returns the pid and process image name listening on port. It returns pid 0 when the owner cannot be determined. NewOwnerLookup returns one that resolves every port of a scan from a single system query.
func NewOwnerLookup ¶
func NewOwnerLookup() OwnerFunc
NewOwnerLookup returns an OwnerFunc that never finds an owner: port remedies are only needed on Windows.
type Status ¶
type Status int
Status is the result of trying to bind a host port.
const ( Free Status = iota // Reserved means the bind was refused although nothing listens on the // port. On Windows this is WSAEACCES, returned for ports inside an // excluded port range reserved by Hyper-V/WinNAT // (`netsh int ipv4 show excludedportrange protocol=tcp`). Docker reports // it as "ports are not available", which reads like the port is in use. Reserved // InUse means a socket is listening on the port. InUse Unavailable )
func Bind ¶
Bind tries to listen on host:port ("" for the wildcard address) and classifies the result.
func ClassifyBindError ¶
ClassifyBindError maps a net.Listen error to a Status.