Next Practical Step
Enable “Use KeepAlive” in HTTP Request Defaults and apply net.ipv4.ip_local_port_range OS tuning on your load injector.
Fix JMeter java.net.BindException Address already in use. Resolve ephemeral port exhaustion, TIME_WAIT socket accumulation, and OS TCP networking bottlenecks.
During high-concurrency load tests or high-throughput API benchmarks, JMeter samplers suddenly start failing en masse with:
Response code: Non HTTP response code: java.net.BindExceptionResponse message: Non HTTP response message: Address already in use: connectOn Linux or macOS load generators, you may also see:
java.net.BindException: Cannot assign requested address (connect failed)The error typically starts after running at high request rates (e.g. 500+ requests per second per injector) for several minutes.
BindException: Address already in use: connect occurs when the operating system running JMeter runs out of available outbound ephemeral ports (temporary client-side TCP ports). When connections are opened and closed rapidly without Keep-Alive, thousands of sockets remain locked in the TIME_WAIT state for 1–4 minutes, blocking new outbound connections.
| Cause | Why it happens |
|---|---|
| HTTP Keep-Alive disabled | Disabling “Use KeepAlive” forces JMeter to open a fresh TCP socket for every single request |
| High request throughput on single IP | Exceeding available ephemeral port capacity (default ~16,000–28,000 ports) on the load generator |
OS TIME_WAIT duration too long | Default TCP TIME_WAIT delay is 60–240 seconds per closed socket before the OS reclaims the port |
| Limited local port range | OS default ip_local_port_range or Windows MaxUserPort is constrained |
| High thread count with short loops | Hundreds of threads executing fast iterations without connection pooling |
The primary prevention for port exhaustion is TCP connection reuse:
Apply sysctl tuning on all Linux JMeter load generator machines:
# 1. Expand the available ephemeral port range (provides ~64,500 ports)sudo sysctl -w net.ipv4.ip_local_port_range="1024 65535"
# 2. Enable fast recycling of TIME_WAIT sockets for outgoing connectionssudo sysctl -w net.ipv4.tcp_tw_reuse=1
# 3. Reduce TCP FIN timeout from 60s to 15ssudo sysctl -w net.ipv4.tcp_fin_timeout=15
# 4. Increase maximum file descriptors and socket backlogsudo sysctl -w fs.file-max=2097152To make these permanent across reboots, add them to /etc/sysctl.conf and run sudo sysctl -p.
TcpTimedWaitDelayOn Windows load generator machines:
# Set TCP dynamic port range to start at 1024 with 64511 portsnetsh int ipv4 set dynamicport tcp start=1024 num=64511regedit and navigate to HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters:
DWORD (32-bit): TcpTimedWaitDelay = 30 (Decimal, reduces TIME_WAIT from 240s to 30s).DWORD (32-bit): MaxUserPort = 65534 (Decimal).If a single IP cannot sustain the required connection rate, configure multiple local IP addresses on the load generator network interface and assign them to JMeter samplers:
192.168.1.101, 192.168.1.102) to the network adapter.\${client_ip}When a single injector reaches its network card or kernel socket capacity, scale horizontally across multiple worker nodes rather than overloading a single instance (distributed testing guide).
| Resource | Use when |
|---|---|
| ConnectException | Connection refused on target host |
| Socket closed / connection reset | Remote server resets connection |
| Distributed testing | Scaling load across multiple load injectors |
| Thread Calculator | Estimating required concurrency and throughput |
Run netstat -an | grep TIME_WAIT | wc -l on Linux or (Get-NetTCPConnection -State TimeWait).Count in Windows PowerShell.
No. Adding more threads increases the rate of socket creation, which accelerates ephemeral port exhaustion. You must enable Keep-Alive or tune OS TCP parameters.
Address already in use: connect is strictly a client-side (load generator) operating system limit. The target server never received the connection attempt because the client OS had no available port to initiate the TCP SYN.