Fix JMeter connection reset and socket closed errors under load: server limits, idle timeouts, keep-alive, injector ports, and TLS drops. Symptom and fixes.
Socket closed / connection reset in JMeter
Section titled “Socket closed / connection reset in JMeter”Symptom
Section titled “Symptom”Samples fail mid-run or under higher concurrency with messages such as:
Connection reset/Connection reset by peerSocket closed/SocketExceptionBroken pipe- Often shown as Non HTTP response code
Unlike pure connection refused, some samples may succeed first; failures increase with load or longer tests.
Common causes
Section titled “Common causes”| Cause | Detail |
|---|---|
| Server or load balancer limits | Max connections, rate limits, or worker exhaustion |
| Idle timeouts | LB/proxy closes keep-alive connections JMeter tries to reuse |
| Injector ephemeral port / file descriptor exhaustion | Many short connections from one host |
| TLS session / middlebox interference | Intermittent handshake or reset under load |
| SUT crash or restart | Bursts of resets when the app dies |
| Aggressive timeouts | Client gives up; appears as socket errors depending on stack |
| Network path instability | VPN, NAT, or multi-hop firewalls |
Fix (ordered)
Section titled “Fix (ordered)”- Capture error rate vs active threads on the dashboard and SUT metrics (connections, 5xx, restarts).
- Reproduce with moderate threads; note whether failures are immediate or after idle.
- Align keep-alive behaviour with the environment (HTTP client settings / connection reuse). If a proxy closes idle sockets quickly, reduce reuse or match idle timeouts.
- Check SUT and LB max connections and idle timeout documentation for your stack.
- On the injector: watch open files, TIME_WAIT, and CPU; split load across engines if the client is saturated (distributed testing, Thread Calculator).
- Distinguish from ConnectException (never connected) vs reset (peer closed an established or half-open connection).
- Review TLS separately if resets cluster around HTTPS only (SSLHandshakeException).
- Ensure you are not melting the SUT with zero think time and huge threads (best practices).
Related tools and topics
Section titled “Related tools and topics”| Resource | Use when |
|---|---|
| Throughput stuck | Resets plus flat RPS |
| OutOfMemoryError heap | Injector death causing drops |
| Coordinated Omission | Throughput below target while latency looks fine |
| Grafana / Backend Listener | Live error charts |
Frequently asked questions
Section titled “Frequently asked questions”Is connection reset always a JMeter bug?
Section titled “Is connection reset always a JMeter bug?”Rarely. It usually means something on the path or server closed the TCP connection. Validate with server and load-balancer metrics.
Why only under load?
Section titled “Why only under load?”Connection pools and OS limits appear only when many sockets are open. One-thread tests often hide them.
Should I disable keep-alive?
Section titled “Should I disable keep-alive?”Sometimes as a diagnostic. Prefer fixing idle timeouts and server capacity; disabling keep-alive increases handshakes and can worsen injector load.