Lab
The port range
A client opens a new connection to one target again and again. Each connect takes a local port from A sysctl: the local ports that a connect can take. The default is 32768 to 60999, thus 28232 ports.. A closed connection can hold its port for a time, for example in The state of a closed connection at the side that closed first. It holds the port for 60 s, thus a late segment cannot reach a new connection.. When each port of a destination is held, a connect gets The error of a connect when no local port is free for its destination. No SYN leaves.. This page computes, in your browser, when the first connect fails and when the first port is free again.
At 28.232 s, a connect gets EADDRNOTAVAIL. Each destination gets 28,232 ports, and each port stays held for 59.999 s to 64.096 s.
- the fault
- the lane acts, in this band
- recovers
- a send again or a timer
- a probe
- measured median of a cell
The axis is logarithmic, thus the first second and the last hour both fit.
The search for a local portA sysctl: the local ports that a connect can take. The default is 32768 to 60999, thus 28232 ports.
First · Knows at 28.232 sEach port that the search reaches is held. Thus a connect at 28.232 s gets EADDRNOTAVAIL at once, and no SYN leaves.
- Ports in the range
- 28,232
- Ports that the search reads
- 28,232
- Connects to one destination, before the error
- 28,232
- Held ports of one destination, at most
- 28,232
- The smallest gap with no error
- 2.27 ms
A sysctl: the local ports that a connect can take. The default is 32768 to 60999, thus 28232 ports.The held portThe state of a closed connection at the side that closed first. It holds the port for 60 s, thus a late segment cannot reach a new connection.
Recovers at 59.999 s to 64.096 sThe client closes first, thus its socket waits in TIME_WAIT. The port is free again at 59.999 s to 64.096 s.
- The side in TIME_WAIT
- the client
- TIME_WAIT
- 60 s
- tcp_tw_reuse
- 2, on loopback only
- Retransmissions of each close
- 0
- PR.5 the client closes first: each port stays held for 60 s from the FIN of the target, plus the wheelMeasured 60.792 s (median of 4 runs)Computed 59.999 s to 64.096 s
Each connectionA sysctl: 1 lets a new connect take a port in TIME_WAIT after tcp_tw_reuse_delay. The default 2 does this on loopback only.The ACK of the FIN of the clientThe clock of the kernel: the ticks in each second. A timer fires on a tick, thus it can be late by one tick or more.
How to read the page
Section titled “How to read the page”- The headline tells when the first connect fails, or why no connect fails.
- The timeline has two lanes. The search lane ends at the first error. The hold lane ends when the first held port comes back. Press Play to see the story.
- The cards below the timeline give each lane, with its knobs. Change a knob, and each time on the page changes.
- An orange dot is the median that a cell of the harness measured. It shows only when your settings are the settings of that cell. Its link opens the cell.
The law of the first error
Section titled “The law of the first error”The client makes one connect each gap, to its d destinations in turn. Thus each destination gets one connect each d · gap. The search of one destination reaches cap ports, and each closed connection holds its port for a time H.
When H is more than cap · d · gap, the connect after the first cap connects of a destination finds no free port. That connect comes at cap · d · gap, and it gets EADDRNOTAVAIL at once. No SYN leaves. Thus the smallest gap with no error is H / (cap · d).
With the defaults of Linux and one connect each 1 ms, connect 28,233 fails at 28.232 s. TIME_WAIT holds each port for 60 s, thus the first port comes back at 60 s.
Where the numbers come from
Section titled “Where the numbers come from”The search for a port is the law of portSearchSpan and portSearchShares of @mark1russell7/algebra. Linux reads the range in two passes. The first pass reads the ports of one parity, and the second pass reads the ports of the other parity.
- An even range gives each of its ports to each destination.
- An odd range can miss one port. Thus a search gets each port of the range, or one port less. For an odd range of 15 ports or fewer, the algebra gives the share of each count.
The time of a held port comes from the timers of the document of Linux TCP, LINUX_TCP of @mark1russell7/machines.
- The client closes first. Its socket waits in TIME_WAIT for 60 s. The timer fires on a tick of The clock of the kernel: the ticks in each second. A timer fires on a tick, thus it can be late by one tick or more., thus the port can come back late. With A sysctl: 1 lets a new connect take a port in TIME_WAIT after tcp_tw_reuse_delay. The default 2 does this on loopback only. 1, a connect takes a port in TIME_WAIT after
tcp_tw_reuse_delay. - The target closes first. The client waits in The state of the side that closed second, until the ACK of its FIN arrives. until the ACK of its FIN arrives, one round trip later. When that ACK drops, the FIN goes again after one Retransmission timeout. TCP sends a segment again if no ACK comes in this time. Each new try waits two times longer..
- A reset holds no port.
Each amount prints through format of @mark1russell7/quantity. The page does no timer arithmetic of its own.
The cells PR.1 to PR.8 measure each law on the runners of GitHub. Their results are on the page of the port range cells.
Limits
Section titled “Limits”- The page makes one connect each gap, at a fixed rate. A client that connects in bursts gets the error at the same count, but sooner.
- A destination is one address and one port of the target. Two ports of one target are two destinations, thus the client gets two times the connects.
- A NAT on the path keeps its own table of connections, with its own limit. This page does not show that table.