ECONNRESET, socket hang up, and broken pipe: what client-side network errors actually mean
Table of contents
- Introduction: why you need to know more about econnreset than "just retry the request"
- Fundamentals: the tcp connection lifecycle and the three points where it breaks
- Deep dive: who actually sends the rst, and why connections "silently" die
- Method 1: a triage framework of "phase, side, pattern, change"
- Method 2: retries that don't corrupt data and don't finish off the server
- Method 3: connection pool and keep-alive hygiene
- Method 4: ip rotation as a first-class event in the client's architecture
- Common mistakes: what turns a harmless drop into an incident
- Tools and resources: how to look without a traffic capture
- Case studies: breaking down typical scenarios
- Faq: questions people ask after reading the basic articles
- Conclusion: from fighting errors to managing them
If you've ever run a scraper, a bot, an API integration, or just a long script firing tens of thousands of HTTP requests, you've seen this: Error: read ECONNRESET, socket hang up, write EPIPE, Connection reset by peer, Broken pipe. A line in the log, a stack trace, and the feeling that the network broke somewhere very far from your code. Sound familiar? That's exactly why ECONNRESET remains one of the most searched errors among developers working with networks, and one of the most misunderstood.
Introduction: why you need to know more about econnreset than "just retry the request"
Most articles about ECONNRESET end with a single piece of advice: wrap the request in a retry. It's not bad advice, but it's incomplete. A retry without understanding the mechanics becomes a lottery: sometimes it saves you, sometimes it duplicates a payment, sometimes it doubles the load on an already overloaded server and finishes it off for good. And a retry tells you nothing about where the connection actually broke: in your process, in the operating system kernel, at the proxy, in the carrier's mobile network, or on the target server.
At Proxeon we watch network drops from a particular vantage point every day: from inside infrastructure where an IP address change isn't an emergency but a routine event. As of 14.11.2026, the entire network processed 2,196,242 IP changes per day, and each one by definition tears down the TCP sessions tied to the old address. In such an environment, connection-drop errors aren't the exception but part of the operating cycle. And oddly enough, that makes it the best possible lab for studying them: when drops are predictable, you can see which client logic survives them and which breaks.
This guide won't dig into tcpdump or reading packet captures: there's already plenty written about traffic-capture tools. Here we'll focus on meaning. You'll learn:
- how ECONNRESET, socket hang up, and broken pipe fundamentally differ, and why they're three distinct signals rather than three names for one problem;
- which phase of a connection's life each error is born in, and who its author is: your process, the OS kernel, an intermediary node, or the remote side;
- how to locate the cause from an error's signature and pattern without a single traffic capture;
- how to build retries, connection pools, and IP rotation handling so that drops are invisible to your business logic;
- which common mistakes turn a harmless connection reset into data loss and service degradation.
This material is aimed at developers, DevOps engineers, and anyone building systems with a large number of outbound connections, especially through proxies. The code is in Node.js and Python, but the principles are the same for Go, Java, Rust, and any other stack: these errors come from the OS kernel, not from the language.
Fundamentals: the TCP connection lifecycle and the three points where it breaks
To understand what ECONNRESET means, you need to recall how a TCP connection lives. Not at the level of headers and flags, but at the level of meaning.
The three phases of a connection's life
Every TCP connection has establishment (the handshake), data exchange, and teardown. Teardown comes in two flavors, and this is the key fork in the road.
- Graceful close (FIN). A side says: "I'm done sending, but I'm ready to accept whatever you haven't sent yet." It's a polite goodbye. Both sides get to flush their buffers, acknowledge receipt, and close in sync.
- Abortive reset (RST). A side says: "this connection no longer exists as far as I'm concerned, stop immediately." No buffers, no waiting. Everything in flight is lost.
Picture a phone call. FIN: the other person says "I've got to go, are we done?", you say "yes," and you both hang up. RST: the line suddenly goes dead mid-sentence. Now imagine you keep talking into the receiver even though you already hear the dial tone. That's the third scenario, covered below.
Where each of the three errors comes from
ECONNRESET (in Linux, the errno named "Connection reset by peer") is generated by your operating system kernel the moment an RST packet arrives on a socket while your process is trying to read from or write to it. Important: the error isn't invented by your application or by the library. It's a literal translation of a network event, "the remote side reset the connection," into the language of a system call. The remote side here isn't necessarily the final server: it's the nearest node your TCP session is with. If you're working through a proxy, the remote side for your socket is always the proxy.
Broken pipe (EPIPE) arises in a different situation. The connection has already been closed by the other side, your process either doesn't know or ignored it, and it keeps writing. The kernel replies: "the pipe is broken, there's nowhere to write." On Unix-like systems the process is also sent a SIGPIPE signal, which by default terminates it. That's the classic beginner story: the program "just crashed without an error." In reality it was killed by a signal, not an exception. Server frameworks and runtimes like Node.js ignore SIGPIPE by default and turn it into an EPIPE error at the code level, but in hand-rolled programs in C, Go, or Python with low-level sockets, you need to remember the signal.
socket hang up is unique in that it's not a kernel error code but a Node.js interpretation. The runtime generates it when an HTTP connection has closed (usually gracefully, via FIN) but no response from the server has started arriving. That is, you sent a request, the server silently closed the connection without so much as a status line. No RST, no read error: just silence and a close. In meaning it's closer to "the other person hung up without saying a word." In other stacks the same situation goes by a different name: in Python via requests you'll see RemoteDisconnected or Connection aborted, in Go it's an EOF error while reading the response, in Java Unexpected end of file from server.
A quick recap to lock it in
- ECONNRESET: the other side sent an RST. Abortive. Data in flight is lost.
- EPIPE / broken pipe: you're writing to an already-closed connection. An error on the write side.
- socket hang up: the connection closed before a response was received. An error at the HTTP protocol level, not TCP.
This recap alone shows that the three errors describe three different moments and three different relationships between your code and the network. That's exactly why a universal "retry everything" often doesn't work.
Deep dive: who actually sends the RST, and why connections "silently" die
Now for the interesting part. The error says "the remote side reset the connection." But who is that side, and why did it do it? There are more possibilities than you'd think.
A map of the reset culprits
The target server. It can reset a connection under overload, when exceeding its limit on concurrent connections, on an error in a handler, on a process restart, or on a request it considers invalid. Many web servers prefer RST over FIN when exceeding their connection limit, because it's cheaper.
An intermediate load balancer or firewall. Stateful network firewalls keep a table of active connections. If a record goes stale (say, a connection has been idle for a long time), the firewall forgets about it. The next packet from you arrives "out of nowhere," and the firewall either silently drops it (you'll get ETIMEDOUT) or replies with RST (ECONNRESET). This is one of the most common causes of resets on long-lived keep-alive connections.
NAT in the carrier's mobile network. Mobile networks almost always work through address translation on the carrier side. The translation table has idle timeouts. When the timeout expires, the return path to your socket disappears. This is critical for mobile proxies: the chain "client, proxy, modem, carrier network, target" contains at least two stateful nodes, each of which can forget about the connection.
A proxy server. A proxy holds two TCP legs: one to you, another to the target. When the second leg breaks, the proxy has to translate that to you somehow. For an HTTP proxy with an ordinary request, that's usually a 502 or 504 response. But for a tunnel via CONNECT (which is all HTTPS traffic) and for SOCKS5, the proxy can't inject a status into the middle of an encrypted stream. All it can do is close your leg: FIN or RST depending on the implementation and the situation. That's why when working through a proxy over HTTPS you see ECONNRESET or socket hang up where over HTTP you'd see a clear response code.
Your own operating system. Yes, it makes the list too. If a process terminated without closing its socket, if the receive buffer overflowed on a closed socket, if close is called on a socket with unread data, the kernel will send an RST in your name. The other side will see ECONNRESET, and you won't see anything at all.
IP changes as a special source of drops
For mobile proxies there's another source that deserves its own discussion. When a modem gets a new IP address, every TCP session established from the old address becomes invalid. A TCP session is identified by an address-and-port pair; if the address changes, then as far as the network is concerned it's a completely different session that nobody knows about. The proxy's outbound connections to target servers die. The proxy, in turn, must close the client tunnels that were tied to those outbound connections. At that moment the client sees the classic set: ECONNRESET on read, EPIPE on write, socket hang up while waiting for a response.
How long does this window last? As of 14.11.2026, the average duration of the IP change itself, from command to the new address appearing, was 4.56 s, while 80.8% of changes finished within 5 seconds. This is an important figure for client design: the instability window is short, but it's not zero, and you need to bake it into your retry and timeout logic.
There's a second aspect too: changes happen en masse and regularly. As of 14.11.2026, 7,924 proxy ports changed IP per day, and the median interval between timer-driven changes was 120 s. If your client holds a keep-alive connection through a proxy port with timer-based rotation, it will reliably hit a drop within a couple of minutes. That's not a defect, it's a property of the environment, and you need to account for it at the architecture level, not at the "caught the exception, retried" level.
The keep-alive race: the most insidious cause of socket hang up
The scenario that deserves special attention reproduces even without a proxy, on any server with keep-alive. The server closes an idle connection on its own timeout. The client decides to reuse that connection from the pool at roughly the same moment and sends a request. The packets cross in the network: a FIN from the server flies to the client, the request from the client flies to the server. The server receives a request on an already-closed socket and replies with RST. The client gets the FIN, then the RST, and not a byte of response. Result: socket hang up or ECONNRESET, depending on which arrived first and when the client tried to read.
This scenario can't be fixed on the server side or the network side. It can only be fixed in the client's configuration: the idle timeout in the client's pool must be noticeably shorter than the server's or proxy's idle timeout. Proxy servers also close idle client connections after their idle timeout, and for HTTP and SOCKS5 those values can differ. The value depends on the specific service's configuration, so the only reliable approach is to keep the client's timeout conservatively short and reopen the connection rather than trusting an old socket after a pause.
Half-open connections
There's also a situation where no RST ever arrives. One side crashed, rebooted, or lost network connectivity without managing to send anything. The other side considers the connection alive. This is a half-open connection. The client can hold it for hours until it tries to send something. Then it will either wait out a timeout (ETIMEDOUT) or, if the remote side has come back to life, get an RST because the remote side knows nothing about the old session. The developer's impression: "ECONNRESET came out of nowhere, the connection was fine." In reality it had been dead for a long time, nobody was just checking.
Method 1: a triage framework of "phase, side, pattern, change"
The first thing to do when a network error appears is not to retry the request but to classify the event. We use a simple four-question framework. It needs no traffic captures and in the vast majority of cases delivers the right hypothesis within minutes.
Question 1: at which phase did the drop happen?
The phase is determined by the error itself and by which call returned it.
- Connection phase. Errors ECONNREFUSED, ETIMEDOUT on connect, EHOSTUNREACH. The connection never got established. This is almost never about your code but about node availability, port, firewall, DNS. If you're working through a proxy, check that you're connecting to the right port: as of 22.09.2026, at Proxeon the SOCKS5 port equals the HTTP port plus one. Pointing an HTTP client at a SOCKS5 port or vice versa produces a whole zoo of errors, from ECONNRESET to strange protocol responses.
- Write phase. EPIPE, write ECONNRESET. The connection existed, you were sending data, and at that moment it turned out the other side had already closed. Typical for large request bodies and for reused pool connections.
- Read phase. read ECONNRESET, socket hang up, Connection aborted, EOF. The request went out, the response never came or was cut off. The most ambiguous phase: here you get server overload, proxy tunnel breaks, and the keep-alive race alike.
- Idle phase. An error on a connection that was doing nothing. This is almost always idle timeouts on the server, proxy, NAT, or firewall.
Question 2: who is the nearest side?
Write down literally: which IP and port the socket was established with. If it's a proxy, then all TCP-level errors refer to the "you and proxy" leg. What happened on the "proxy and target" leg you can't learn from a TCP error. For an HTTP proxy, correlate: if the proxy managed to reply with a 502, 504, or similar status, the problem was on the far leg. If there was no response at all, the problem is either on the near leg or the proxy closed the tunnel because of the far leg.
Question 3: what's the error pattern over time?
This is the most underrated question. Collect the error timestamps over an hour and look at the distribution.
- Single, rare, random. Network noise. Fix it with retries, nothing else is needed.
- Bursts every N seconds at a regular interval. This is almost certainly a scheduled event: timer rotation, a service restart, log rotation on the server, a load balancer resetting connections. If you see regular bursts roughly every two minutes on a proxy port, recall the median timer-rotation interval from the data above and check the port settings.
- Bursts that coincide with your actions. You called the IP-change link and got a series of ECONNRESET a few seconds later. This is expected behavior, and the only remaining question is how your code handles it.
- Increasing frequency. The server or proxy is degrading under your own load. Retries hurt here: they make the problem worse.
- Errors only on long-lived connections. A classic idle timeout somewhere in the chain.
Question 4: what changed?
Did you update the HTTP client library? Switch Node.js or Python versions? Enable keep-alive that used to be off? Increase concurrency? Move from an HTTP port to SOCKS5? The vast majority of "sudden" ECONNRESET spikes have a specific commit or a specific configuration change behind them. If you didn't change anything, someone else in the chain did, and then the pattern from question 3 will tell you who.
Triage checklist
- Record the exact error string, including the operation prefix (read, write, connect).
- Determine the phase: connection, write, read, idle.
- Note the nearest socket side and the protocol (HTTP, CONNECT tunnel, SOCKS5).
- Collect timestamps over a representative period and describe the pattern.
- Correlate the pattern with known periodic events: IP rotation, restarts, timeouts.
- List all code and configuration changes over the past few days.
- Formulate one hypothesis and one way to test it before changing anything.
Method 2: retries that don't corrupt data and don't finish off the server
After triage, it almost always turns out that some errors have to be accepted as a given and handled with retries. But a retry must be designed, not bolted on from the outside.
The idempotency principle
Only operations that are safe to perform twice can be retried. GET, HEAD, and OPTIONS are idempotent by definition. PUT and DELETE are idempotent by protocol semantics, provided the server adheres to them. POST is not idempotent, and here the most dangerous question appears: did the request reach the server before the connection broke?
The answer depends on the phase. If the error occurred in the write phase (EPIPE, write ECONNRESET), the request most likely wasn't processed. If in the read phase (read ECONNRESET, socket hang up), the server may have received and processed the request but failed to respond. Retrying a POST after a read error without protection is unacceptable. The standard protection is an idempotency key in a header that the server uses for deduplication, or a state check before retrying (for example, a query "does an order with this client ID exist?").
Which errors to retry, which not to
- Retry: ECONNRESET, EPIPE, socket hang up, ETIMEDOUT, EAI_AGAIN (temporary DNS error), premature stream-close errors, 502, 503, 504 statuses from a proxy or server.
- Retry with caution: ECONNREFUSED. If the port refuses consistently, retries are pointless; if it's during a restart, they'll help. Limit the number of attempts more strictly.
- Don't retry: protocol errors (malformed response, parse error), 4xx statuses other than 408 and 429, proxy authentication errors. Retrying here only wastes resources and masks the real problem.
Exponential backoff with jitter
Retrying immediately after an error almost always lands in the same instability window. The delay must grow with each attempt, and to keep thousands of clients from hitting the server synchronously after recovery, a random component is added to the delay. For environments with IP rotation it helps to remember that the change window itself fits within a few seconds: as of 14.11.2026, 80.8% of changes finished within 5 seconds. That means the second or third attempt with growing backoff will very likely land outside the window.
A retry budget instead of a counter
The "three attempts per request" counter works well for a single request and poorly for a system. If you have a thousand parallel tasks and each has three retries, during a mass drop you'll generate three times the load than before. A more mature approach is a shared retry budget per unit of time for the entire client. When the budget is exhausted, new errors aren't retried but surfaced upward. This is a natural defense against cascading degradation.
Example: Node.js
const RETRYABLE = new Set(['ECONNRESET', 'EPIPE', 'ETIMEDOUT', 'EAI_AGAIN', 'ECONNREFUSED']);function isRetryable(err) { if (RETRYABLE.has(err.code)) return true; if (err.message && err.message.includes('socket hang up')) return true; if (err.response && [502, 503, 504].includes(err.response.status)) return true; return false;}async function withRetry(fn, { attempts = 4, baseMs = 500 } = {}) { let lastErr; for (let i = 0; i < attempts; i++) {try { return await fn(); } catch (err) { lastErr = err; if (!isRetryable(err) || i === attempts - 1) throw err; const delay = baseMs * Math.pow(2, i) + Math.random() * baseMs; await new Promise(r => setTimeout(r, delay));} } throw lastErr;}Example: Python with requests and urllib3
from requests.adapters import HTTPAdapterfrom urllib3.util.retry import Retryretry = Retry(total=4, backoff_factor=0.5, status_forcelist=[502, 503, 504], allowed_methods=['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS'], raise_on_status=False)adapter = HTTPAdapter(max_retries=retry, pool_connections=16, pool_maxsize=16)session = requests.Session()session.mount('http://', adapter)session.mount('https://', adapter)session.proxies = {'http': 'http://user:pass@host:port', 'https': 'http://user:pass@host:port'}Note: POST is deliberately absent from allowed_methods. For POST, the retry is done manually, with an idempotency key and only after checking the error phase.
Retry checklist
- Classify the error as retryable or not by code and phase.
- For non-idempotent operations, provide an idempotency key or a state check.
- Use exponential backoff with jitter.
- Limit the number of attempts and the overall retry budget per client.
- Log every attempt with the error code, phase, and attempt number.
- When the budget is exhausted, don't swallow the error but surface it with full context.
Method 3: connection pool and keep-alive hygiene
If retries treat the symptoms, proper connection pool configuration removes the cause of most socket hang up errors and a significant share of ECONNRESET. The pool is where connections live between requests, and it's exactly where they die quietly.
The rule of synchronized timeouts
The main rule goes like this: the idle timeout in the client must be strictly shorter than the shortest idle timeout in the chain. In the "client, proxy, carrier NAT, server" chain, every node has its own idea of how long silence is allowed. You only know your own value. The others are either documented or not. So the strategy is simple: set a conservatively short idle timeout and don't be shy about reopening connections. The cost of a new TCP handshake, or even a TLS handshake, is nothing compared to the cost of a lost request and a retry.
Configuring the agent in Node.js
The standard http.Agent in modern Node.js versions supports keep-alive and a cap on the number of sockets. The key parameters:
- keepAlive: enable reuse. Without it, every connection closes after the response, which removes the race problem but adds extra handshakes.
- maxSockets: a cap on parallel connections per host. This protects against exceeding limits on the proxy and server side. Every proxy port has a ceiling on simultaneous connections, beyond which new ones are reset; the specific value depends on the plan and configuration, so check the docs and keep concurrency with a margin.
- timeout at the socket level: protection against half-open connections. If no data moves for longer than the timeout, the socket is closed and reopened.
Worth mentioning separately is undici, the modern HTTP client built into Node.js. It has explicit keepAliveTimeout and keepAliveMaxTimeout parameters, and errors look different there: instead of socket hang up you'll see UND_ERR_SOCKET with the description "other side closed." The meaning is the same, the handling is the same, but string matching on the message will break. Go by the error code, not the text.
Protection against EPIPE
Broken pipe on write is especially common when sending large bodies: files, batches, streams. The connection closed halfway through and your code keeps writing chunks. Protection: subscribe to socket close events and stop writing, use stream backpressure, check the state before writing each large chunk. In Python, when working with sockets directly, don't forget to ignore or catch SIGPIPE, otherwise the process will terminate without an exception.
When to disable keep-alive
There's a scenario where keep-alive is harmful: working through a proxy port with frequent IP rotation, where each request must go out from a new address. A connection reused after an IP change either doesn't exist or (worse) the tunnel wasn't torn down and the request will go out from the old address. The right approach: one request, one connection, a Connection: close header, and the pool disabled for that host. This is an example of how a "best practice" (reuse) becomes an error source in the wrong context.
Pool checklist
- The client's idle timeout is shorter than any known timeout in the chain.
- A cap on parallel connections per host and per proxy port.
- An inactivity timeout on the socket to protect against half-open connections.
- EPIPE handling in the write phase, backpressure for streams.
- An explicit decision: keep-alive on or off for each class of targets.
- Check the error code, not the message text, when classifying.
Method 4: IP rotation as a first-class event in the client's architecture
This method is specific to working through proxies with dynamic addresses, but that's exactly where most teams lose the most time. The reason is simple: rotation is treated as an external nuisance rather than a managed event.
Two IP change modes and their consequences
As of 22.09.2026, an IP change on a port can happen in two ways: by timer and by link or API. As of 14.11.2026, the share of timer-based changes was 51.1%, with the rest being link- and API-driven. For client architecture these are fundamentally different worlds.
Timer mode. The change happens without your involvement at a set interval. The median interval as of 14.11.2026 was 120 s. Your client doesn't know the exact moment but knows the period. Consequence: no connection lives longer than the interval, long downloads may not finish, and keep-alive is useless beyond the interval horizon. ECONNRESET and socket hang up errors will come in regular bursts, and that's normal.
Link or API mode. The change happens on your command. You know the start moment exactly and can wait for completion. This is the mode for those who want control: finish the current batch of requests, change the IP, wait for the new address, start the next batch. There may be no connection-drop errors at all in this mode if the client is properly built.
The client state machine
We recommend describing work with a proxy port as a four-state machine.
- ACTIVE: connections are opened and used, retries run as usual.
- DRAINING: a decision to change has been made, new requests aren't started, current ones complete with a short deadline.
- ROTATING: the change command has been sent, all connections through the port have been closed by the client (to get a FIN from yourself rather than an RST from the proxy), and confirmation of the new address is awaited.
- SETTLING: the new address has been received, a single probe request is made, and on success we transition to ACTIVE.
The ROTATING to SETTLING transition takes 4.56 s on average as of 14.11.2026. That means in API mode the pause is practically unnoticeable, and drop errors are replaced by a managed pause. The difference is huge: instead of unpredictable exceptions in random places in your code, you get one expected event in one place.
How to close connections before a change
A subtlety rarely discussed. If you close connections yourself before the change command, you send a FIN and the proxy cleanly tears down the tunnels. If you leave connections open, the proxy is forced to close them from its side during the change, and depending on the moment you'll get a FIN or an RST. By closing first, you move the situation from "error" to "normal termination." In Node.js it's agent.destroy(), in Python it's session.close() followed by creating a new session, in Go it's CloseIdleConnections on the transport.
Recognizing rotation by pattern in timer mode
If you're in timer mode and can't control the moment of change, use the error pattern as a signal. A burst of drops on one port within a few seconds, after which connections establish again, is rotation. The client can react to that signal by temporarily moving the port to SETTLING: pause new requests for a few seconds, then make a probe request and return to ACTIVE. This reduces the number of pointless retries inside the instability window.
Don't mix up protocols
Let's repeat once more: the SOCKS5 port equals the HTTP port plus one as of 22.09.2026. An off-by-one error in configuration produces symptoms indistinguishable from network issues: the client sends a SOCKS5 handshake to the HTTP port, the proxy doesn't understand the bytes and closes the connection. You see ECONNRESET or socket hang up and start looking for a network problem that doesn't exist. The first thing to check with consistent drops in the connection or first-request phase is whether the protocol and port match.
Rotation checklist
- Determine the change mode for every port: timer or API.
- For API mode, implement the state machine with explicit DRAINING and ROTATING.
- Close connections on the client before the change command.
- After the change, make a probe request before resuming load.
- For timer mode, recognize a burst of drops as a rotation signal and pause requests.
- Verify that the protocol and port number match.
- Disable keep-alive if every request must go out from a new address.
Common mistakes: what turns a harmless drop into an incident
Over the years of watching ECONNRESET-related tickets, we've identified mistakes that recur from project to project regardless of language or team experience.
Mistake 1: retrying without classification
A single handler for all exceptions: caught it, waited a second, retried. As a result, proxy authentication errors get retried, POSTs without idempotency get retried, and requests to a failing server get retried until it completely falls over. Classification by code and phase is essential.
Mistake 2: matching on message text
Code like "if the message contains the word 'reset'." Message text differs across runtimes, library versions, and locales. The recent move to undici in Node.js broke a ton of such checks because the text changed. Use the error code and exception type.
Mistake 3: no timeout at all
A request without a timeout on a half-open connection hangs until the kernel gives up, which can take a very long time. Hung tasks pile up, the pool is exhausted, the system degrades without a single error in the logs. You need timeouts on the connection, on waiting for headers, and on the entire request.
Mistake 4: ignoring SIGPIPE
A process in Python or Go with hand-rolled socket work silently disappears. Nothing in the logs. In reality it was terminated by a signal while writing to a closed connection. Check the process exit code and set up signal handling.
Mistake 5: unlimited concurrency
A thousand parallel connections through one proxy port. A cap on simultaneous connections per port always exists, and beyond it new connections are reset. The developer sees ECONNRESET and ECONNREFUSED and looks for a network problem, when the cause is their own load. Cap the concurrency and measure it.
Mistake 6: retries on top of retries
The HTTP client library retries on its own, a wrapper on top retries again, an outer task queue retries a third time. In total, one request during a failure turns into dozens. Retries must be at exactly one level, and it must be explicitly chosen.
Mistake 7: mixing IP changes and ordinary failures in the metrics
All drops land in a single "network errors" metric. The regular bursts from timer rotation mask rare real incidents. Separate the metrics: drops inside the rotation window and drops outside it. Then alerts will fire on what actually matters.
Mistake 8: trusting an old connection after a long pause
The client made a request, then spent half an hour processing data, then took the same connection from the pool. It was long since closed by the server, the proxy, and NAT. The first request after the pause fails with socket hang up. Solution: a short idle timeout in the pool, or a forced reopen after a pause.
Tools and resources: how to look without a traffic capture
We agreed not to go deep into packet capture. The good news: for the vast majority of cases it isn't needed. Here are the tools that give you understanding without analyzing captures.
Detailed HTTP client logs
- Node.js: the NODE_DEBUG environment variable with the values net, http, tls shows the lifecycle of every socket: opening, reuse, closing, reason. For undici there's diagnostics_channel with events for each request phase.
- Python: enabling the urllib3 logger at DEBUG shows when a connection is taken from the pool, when a new one is created, when a retry happens and why.
- Go: the net/http/httptrace package gives hooks for getting a connection, starting a write, and the first response byte. The main question, "was the connection reused," is answered by a single field in the trace.
- curl: verbose flags with timestamps show every phase to the millisecond. This is the fastest way to reproduce the problem outside your code and figure out where it is: in the code or in the network.
Socket state in the system
The ss utility in Linux shows all sockets with their states. If you see a lot of sockets in CLOSE-WAIT, your process received a FIN and didn't close the socket on its side: that's a leak, and the next write to such a socket will produce an EPIPE. A lot of sockets in TIME-WAIT means you're closing connections first and very often: that's normal, but it can hit port limits under high load. For diagnostics without a traffic capture, ss is often more informative than any other tool.
System call tracing
strace in Linux shows exactly which call returned the error: read, write, connect, sendto. This pins down the drop phase unambiguously, and the phase, as we've seen, is half the diagnosis. It's a heavy tool for production, but indispensable for reproducing on a staging box.
Metrics and observability
Collect at least:
- an error counter broken down by code (ECONNRESET, EPIPE, hang up, timeout) and phase;
- a retry counter broken down by attempt number and outcome;
- the number of active connections in the pool and the number of reuses;
- the timestamp of the last IP change on each port, to correlate drops with the rotation window;
- request duration percentiles, separately for the first request on a new connection and for a reused one.
Such metrics let you see the keep-alive race (errors only on reused connections), rotation (errors in the change window), and overload (errors growing with concurrency) without a single capture.
Documentation and primary sources
To understand the semantics of error codes, the primary source remains your operating system's manual pages for the connect, send, and recv system calls and the errno descriptions. For HTTP clients, read the documentation on pool and retry parameters for the exact version you're using: default behavior has changed between major Node.js versions and between urllib3 versions. For proxies, study the provider's documentation on IP change modes, port mapping, and connection limits: that's where the numbers you need to bake into timeouts live.
Case studies: breaking down typical scenarios
Below are three breakdowns built on typical tickets. Numbers and project names are deliberately omitted: the value is in the diagnostic logic, not in the details of a specific incident.
Scenario 1: a scraper with regular socket hang up bursts
Symptom. A Node.js scraper with a connection pool through a mobile proxy port. Every couple of minutes a burst of socket hang up, then everything works. The team suspects proxy instability.
Triage. Phase: read. Nearest side: proxy, CONNECT tunnel. Pattern: regular bursts with a constant period. Changes: keep-alive was recently enabled for speed.
Diagnosis. The port is running in timer-based change mode. On each change the tunnels are closed, but the client pool holds connections longer than the change interval and tries to reuse them. The problem isn't in the network or the proxy but in the mismatch between the pool strategy and the rotation mode.
Solution. Two options. First: switch the port to API change mode and implement the state machine with connection closing before the change. Second: keep the timer but limit the connection lifetime in the pool to noticeably less than the change interval and treat a burst of drops as a rotation signal with a short pause. The team chose the first option because it needed to control which requests went out from which address.
Result. socket hang up disappeared from the logs as a class; in its place there's one "rotation" event with a measurable duration. Retries remained but started firing only on real network failures.
Scenario 2: a payment API integration and duplicate operations
Symptom. A Python service sends a POST to an external API. Occasionally ECONNRESET on reading the response, the retry fires, and duplicate operations appear on the partner's system.
Triage. Phase: read. That means the server may have processed the request before the drop. Pattern: rare single errors, network noise. Changes: none.
Diagnosis. Retries are configured universally, including POST without an idempotency key. When a drop happens in the read phase, the request is retried, and the partner processes it a second time.
Solution. Split retries by phase: retry freely on write errors, and for read-phase errors on non-idempotent operations, first query the operation state by client ID and retry only if it's absent. Add an idempotency key in a header, since the partner's API supported it.
Result. Duplicates stopped. The frequency of ECONNRESET didn't change, and that's an important takeaway: not every network error needs to be eliminated, sometimes it's enough to make it safe.
Scenario 3: a large-file uploader and broken pipe
Symptom. A Go service uploads large files through a SOCKS5 port. Periodically the logs show "broken pipe," and sometimes the process terminates without an error.
Triage. Phase: write. Nearest side: proxy, SOCKS5. Pattern: correlates with upload duration; the larger the file, the more likely the error. Changes: switched from an HTTP port to SOCKS5 and made an off-by-one mistake in the port number in some environments.
Diagnosis. Two independent problems. First: in some environments the SOCKS5 client connected to the HTTP port, the proxy closed the connection after the first handshake bytes, and the client got a drop on the first write. Second: uploads lasting longer than the IP change interval on a timer port were cut off midway; the process sometimes got a signal while writing to a closed socket.
Solution. Fix the port mapping by the "SOCKS5 equals HTTP plus one" rule. For long uploads, switch the port to API change mode and forbid changes while an upload is in progress (a DRAINING state with a long deadline). Add signal handling and a closed-socket check before writing each large chunk.
Result. Drops on the first write disappeared immediately after the port fix. Drops on long uploads disappeared after moving to managed rotation. The process stopped terminating without an error.
FAQ: questions people ask after reading the basic articles
Are ECONNRESET and socket hang up the same thing?
No. ECONNRESET is a TCP-level error: an RST packet arrived, the connection was abortively reset. socket hang up is a Node.js interpretation at the HTTP level: the connection closed (usually gracefully) before a response was received. The first tells you how the connection closed, the second tells you when. They can arise in the same situation depending on the packet race, but they should be classified separately: socket hang up on a reused connection almost always points to a keep-alive race.
Why do I see ECONNRESET through a proxy where without one I'd get a clear response code?
Because for an HTTPS tunnel and for SOCKS5, the proxy can't inject a response code into an encrypted stream. If the far leg breaks, the only way to tell you is to close your leg. You see a TCP error instead of an HTTP status. This isn't the proxy losing information but a limitation of the tunneling protocol. For plain HTTP without a tunnel, a proxy will typically reply with a 502 or 504 status.
Should I retry a request on EPIPE?
As a rule, yes, and it's one of the safest cases for a retry. EPIPE means the connection closed before you finished sending the request. The server either didn't receive it at all or received it incomplete and didn't process it. The risk of a duplicate is minimal. But the retry must go over a new connection: the old one is dead.
How do I know a drop is tied to an IP change and not a server problem?
By the pattern and by time alignment. Correlate the error timestamps with the IP-change timestamps on the port: in API mode you know them exactly, in timer mode you know the period. If errors cluster into short windows around a change, it's rotation. As of 14.11.2026, the change itself takes 4.56 s on average, so the instability window is short. Errors spread evenly over time or growing with load aren't tied to rotation.
Should I even enable keep-alive when working through a rotating proxy?
It depends on the task. If you need maximum speed and you're in API change mode with explicit connection closing before the change, keep-alive gives a win and is safe. If the port runs on a timer and you don't control the change moment, keep-alive is acceptable with a connection lifetime substantially shorter than the change interval. If every request must go out from a new address, keep-alive must be off. There's no universal answer, only a deliberate choice for the scenario.
Why did errors appear after a library update when the code didn't change?
Most often the defaults changed: keep-alive got enabled, the pool idle timeout changed, the error message text changed. Any of these can cause a spike. Check the changelog for major versions of your HTTP client and set all pool parameters explicitly rather than relying on defaults. Explicit configuration survives upgrades, implicit doesn't.
What should I do if errors only appear under high load?
Look for limits. A proxy port has a ceiling on simultaneous connections, the target server has limits, the system has limits on file descriptors and ephemeral ports. When you hit any of them, new connections are reset, and you see ECONNRESET or ECONNREFUSED. Retries only make it worse here. Cap the concurrency, measure at what level it starts producing errors, and stay below it with a margin.
Can I get rid of ECONNRESET entirely?
No, and you shouldn't try. The network is inherently unreliable, and in an environment with IP rotation, drops are part of the normal cycle. The realistic goal is different: make it so that no such error reaches business logic and causes data loss or duplication. That's achieved through classification, proper retries, pool hygiene, and rotation management, not through fighting the error itself.
How does handling errors on an HTTP port differ from a SOCKS5 port?
At the TCP level, not at all: both produce the same ECONNRESET, EPIPE, and closes. The difference is that an HTTP proxy can return a status for non-tunneled requests, while SOCKS5 always works as a tunnel and returns no statuses. So on SOCKS5 all far-leg diagnosis comes down to TCP errors, and the time pattern becomes the only source of information about the cause. And don't forget the port mapping: SOCKS5 equals HTTP plus one as of 22.09.2026.
Conclusion: from fighting errors to managing them
Let's sum up. ECONNRESET, socket hang up, and broken pipe aren't three names for one problem but three different messages about three different moments in a connection's life. ECONNRESET tells you about an abortive reset by the remote side. Broken pipe tells you you're writing to an already-dead connection. socket hang up tells you the connection closed before a response was received. Each has its own phase, its typical cause, and its safe handling strategy.
We've covered four methods that together form a complete system for working with network drops:
- triage by phase, side, pattern, and change, which delivers a hypothesis without traffic captures;
- retries with classification, idempotency, exponential backoff, and a budget;
- connection pool hygiene with synchronized timeouts and a deliberate keep-alive choice;
- IP rotation as a managed first-class event with a state machine.
The main mindset shift we want to offer you: stop treating network errors as the enemy. In an environment where, as of 14.11.2026, 2,196,242 IP changes happen per day across 7,924 ports, drops are the rhythm of the system, not its failure. A client that understands this rhythm and is designed for it runs stably. A client that fights the rhythm breaks down unpredictably.
Next steps
- Open your logs for the last 24 hours and classify errors by phase. That alone will show where you have a keep-alive race and where you have rotation.
- Verify that retries are enabled at exactly one level and don't touch non-idempotent operations without protection.
- Explicitly set all connection pool parameters and timeouts rather than relying on library defaults.
- If you work through a rotating proxy, determine the change mode for each port and pick a strategy: managed change via API or adaptation to the timer.
- Split drop metrics into "inside the rotation window" and "outside the window" so alerts fire on real incidents.
Client network errors stop being a mystery the moment you start reading them as messages rather than as noise. We hope this guide becomes your bookmark for the day the familiar line read ECONNRESET shows up in the logs again, and you already know which four questions to ask first.