# ephemeral ports

Ports chosen automatically by a networking stack for client connections are known as ephemeral ports.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## We Ran Out of TCP Ports at 1:30 AM -- the Crack Was tcp\_tw\_reuse=0

DevFeed: [We Ran Out of TCP Ports at 1:30 AM -- the Crack Was tcp\_tw\_reuse=0](<https://devfeed.tech/articles/we-ran-out-of-tcp-ports-at-1-30-am-the-crack-was-tcp-tw-reuse-0-26518.md>)

Original publisher: [Read original article](<https://medium.com/engineering-housing/we-ran-out-of-tcp-ports-at-1-30-am-the-crack-was-tcp-tw-reuse-0-54952bf5f7bd?source=rss----3a69e32e2594---4>)

Author: PULKIT GARG

Published: 2026-08-11T05:58:23Z

Content type: article

Language: en

Sources: [Housing.com](<https://devfeed.tech/sources/housing-com.md>)

Topics: [ephemeral ports](<https://devfeed.tech/topics/ephemeral-ports.md>), [Kernel](<https://devfeed.tech/topics/kernel.md>), [hosting](<https://devfeed.tech/topics/hosting.md>), [Post Mortem](<https://devfeed.tech/topics/post-mortem.md>), [observability](<https://devfeed.tech/topics/observability.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>)

Tags: [alerting](<https://devfeed.tech/tags/alerting.md>), [apis](<https://devfeed.tech/tags/apis.md>), [app](<https://devfeed.tech/tags/app.md>), [apps](<https://devfeed.tech/tags/apps.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [background](<https://devfeed.tech/tags/background.md>), [box](<https://devfeed.tech/tags/box.md>), [bug](<https://devfeed.tech/tags/bug.md>), [code](<https://devfeed.tech/tags/code.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [ephemeral](<https://devfeed.tech/tags/ephemeral.md>), [ephemeral-ports](<https://devfeed.tech/tags/ephemeral-ports.md>), [error](<https://devfeed.tech/tags/error.md>), [errors](<https://devfeed.tech/tags/errors.md>), [job](<https://devfeed.tech/tags/job.md>), [jobs](<https://devfeed.tech/tags/jobs.md>), [kernel](<https://devfeed.tech/tags/kernel.md>), [machine](<https://devfeed.tech/tags/machine.md>), [production-issue](<https://devfeed.tech/tags/production-issue.md>), [reuse](<https://devfeed.tech/tags/reuse.md>), [ruby-on-rails](<https://devfeed.tech/tags/ruby-on-rails.md>), [tcp](<https://devfeed.tech/tags/tcp.md>)

### AI overview

A shared host ran out of ephemeral TCP ports during an unrelated neighbor's overnight bulk job, causing about 7,800 background-job failures across two nights. The neighbor's burst reached roughly 93,000 outbound calls per minute; both services opened a new connection per call, and closed connections remained in TIME_WAIT while tcp_tw_reuse was off. Immediate three-attempt retries added pressure. The article says enabling net.ipv4.tcp_tw_reuse = 1 provided a quick capacity increase, but presents persistent pooled keep-alive connections and exponential backoff as the architectural fix. It also recommends managing kernel settings through provisioning, since a host replacement had reset them. The account attributes recovery to the neighbor's batch ending and describes the incidents as intermittent.

### Source excerpt

A neighbor's bulk job drained every ephemeral port on a shared box. Twice. Here's the one kernel setting that would have stopped it -- and the architecture that makes it a non-issue. At 1:38 AM, one of our background-job services started failing. Scheduled jobs -- the nudges and reminders we send users overnight -- began throwing an error most engineers rarely see: Errno::EADDRNOTAVAIL -- Cannot assign requested address Not "connection refused." Not "timeout." Cannot assign requested address. The machine wasn't saying the other end was down. It was saying it had run out of addresses to call from. Here's the strange part: we hadn't deployed anything. Our code was untouched for days. And by ~3 AM it healed itself, with nobody doing a thing. Two nights later, same window, it happened again. The bug wasn't in our service. It was in a service we don't own -- and don't even talk to. Act 1: A crime scene with no suspect ~7,800 job executions failed across the two nights. The first night slipped in under the alerting threshold entirely -- we only found it in the errors inbox after the fact. Everything about it was confusing: Our service hadn't changed. The internal APIs we call were all healthy. It happened in a tight window (~1:30-3:00 AM), then vanished. No human fixed it. It just... stopped. An outage that fixes itself is telling you something important: the thing that broke wasn't yours, and the pressure that caused it was temporary. Act 2: The noisy neighbor That service doesn't run on its own machine. It shares one box with about ten other apps -- a normal, cost-efficient setup. What's easy to forget is what they silently share: not just CPU and memory, but the operating system's ephemeral port pool. Quick refresher. Every time a program opens an outbound TCP connection, the OS assigns it a temporary "ephemeral" source port. That pool is finite -- by default, roughly 28,000 ports. And on a shared box, every app draws from the same pool. Ephemeral ports are an unmonitored, multi

## Bind before connect

DevFeed: [Bind before connect](<https://devfeed.tech/articles/bind-before-connect-38934.md>)

Original publisher: [Read original article](<https://idea.popcount.org/2014-04-03-bind-before-connect>)

Author: Marek

Published: 2014-04-02T22:00:00Z

Content type: article

Language: en

Sources: [Marek Majkowski](<https://devfeed.tech/sources/marek-majkowski.md>)

Topics: [Linux Kernel](<https://devfeed.tech/topics/linux-kernel.md>), [ephemeral ports](<https://devfeed.tech/topics/ephemeral-ports.md>), [Kernel](<https://devfeed.tech/topics/kernel.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [article](<https://devfeed.tech/tags/article.md>), [automatically](<https://devfeed.tech/tags/automatically.md>), [bind](<https://devfeed.tech/tags/bind.md>), [bsd](<https://devfeed.tech/tags/bsd.md>), [call](<https://devfeed.tech/tags/call.md>), [connect](<https://devfeed.tech/tags/connect.md>), [ephemeral](<https://devfeed.tech/tags/ephemeral.md>), [ip](<https://devfeed.tech/tags/ip.md>), [kernel](<https://devfeed.tech/tags/kernel.md>), [linux](<https://devfeed.tech/tags/linux.md>), [linux-kernel](<https://devfeed.tech/tags/linux-kernel.md>), [number](<https://devfeed.tech/tags/number.md>), [operating-system](<https://devfeed.tech/tags/operating-system.md>), [port](<https://devfeed.tech/tags/port.md>), [range](<https://devfeed.tech/tags/range.md>), [socket](<https://devfeed.tech/tags/socket.md>), [source](<https://devfeed.tech/tags/source.md>), [system](<https://devfeed.tech/tags/system.md>), [tcp](<https://devfeed.tech/tags/tcp.md>)

### AI overview

Linux normally selects an ephemeral source port during `connect()`, allowing the same port to serve connections to different destinations; the excerpt says more than 28,000 simultaneous connections to one destination pair will fail by default. Binding a source IP first changes allocation: without reuse, a port is effectively tied up regardless of destination. Setting `SO_REUSEADDR` permits sharing across nonconflicting connections, including cases involving established or `TIME_WAIT` sockets, but a later `connect()` can still fail with `EADDRNOTAVAIL` if the chosen port conflicts, so retry may be needed. The excerpt recommends expanding the port range and using multiple source IPs for higher connection counts, and warns that `connect()` and bind-before-connect allocations interfere with each other. It distinguishes `SO_REUSEPORT` as primarily for distributing incoming traffic among sockets. These are the article's described Linux behaviors and caveats.

### Source excerpt

Bind before connect A TCP/IP connection is identified by a four element tuple: {source IP, source port, destination IP, destination port}. To establish a TCP/IP connection only a destination IP and port number are needed, the operating system automatically selects source IP and port. This article explains how the Linux kernel does the source port allocation. Ephemeral port range To establish a connection BSD API requires two steps: first you need to create a socket, then call on it.