HTTP Client Timeouts Through a Proxy: Connect, Read, Write, and the Overall Request Budget
Table of contents
- Introduction: why timeouts through a proxy deserve their own conversation
- Fundamentals: what a timeout is and what phases a request consists of
- Deep dive: what physically happens when each timeout fires
- Method 1: setting connect timeout with two hops in mind
- Method 2: read timeout as an idle interval and protecting the first byte
- Method 3: write timeout and handling large request bodies
- Method 4: the overall request budget and deadline propagation
- Method 5: timeout observability and adaptive tuning
- Common mistakes: what not to do
- Tools and resources
- Case studies and results
- Faq: tricky questions about timeouts through a proxy
- Conclusion: timeouts as an engineering discipline
Introduction: Why Timeouts Through a Proxy Deserve Their Own Conversation
Picture this: your scraper has been running for three days straight, burning through mobile proxy traffic, and half the records come back empty, with logs stuffed full of timeout, connection reset, and remote end closed connection. Sound familiar? We've seen dozens of systems like this, and the root cause is almost always the same: timeouts set by gut feeling — one magic number like 30 seconds for everything. Over a direct connection, that sort of works. Through a proxy, especially a mobile one, it doesn't.
The thing is, a proxy adds another network segment, another set of queues, and another node with its own timeouts to the chain. A request doesn't go through one waiting phase — it goes through five or six, and you can get stuck at each one for different reasons. A single overall limit can't tell you where you got stuck: on the TCP handshake with the proxy, on establishing the tunnel to the target site, on a slow first byte of the response, or on transferring a large body.
This article is about the architecture of waiting. We'll break down the phases an HTTP request through a proxy consists of, which timeout governs each phase, what physically happens when it fires, and how to combine individual limits into a coherent overall budget. It's important to immediately separate this from an adjacent topic: here we are not discussing 429 or 503 response codes or retry strategies with exponential backoff. That's a separate layer — reacting to the server having already responded. Here we're talking about situations where there's no response at all, and how long we're willing to wait for one at each level.
After reading this, you'll be able to: break down any request into phases and assign each its own limit; explain why the client showed a timeout while the server still performed the action; correctly align client, connection pool, and proxy timeouts; and, most importantly, stop losing data and money on pointless waiting.
Fundamentals: What a Timeout Is and What Phases a Request Consists Of
Timeout as a Contract for Waiting
A timeout is the maximum time a client is willing to wait for a specific event to occur before declaring the attempt failed and releasing resources. The key word here is specific. There's no such thing as a "request timeout in general." There's a timeout for establishing a TCP connection, a timeout for the TLS handshake, a timeout for waiting for data from the socket, a timeout for writing to the socket, a timeout for waiting for a free connection in the pool, and finally, an overall deadline for the entire operation.
A good analogy is a trip with transfers. You have time to get to the station, time waiting for the train, time in transit, time for the transfer. And there's an overall limit: you need to be at a meeting by nine in the morning. If you only control the overall limit, you'll find out about a problem when you're already late. If you control each stage, you can make a decision in advance: take a taxi, for instance, because the bus hasn't shown up in ten minutes.
Phases of an HTTP Request Over a Direct Connection
Even without a proxy, a request is a sequence of steps:
- Name resolution (DNS). The client turns a domain name into an IP address. Usually takes milliseconds to hundreds of milliseconds, but with resolver issues it can hang for seconds.
- TCP connection. The three-way handshake: SYN, SYN-ACK, ACK. Requires one full round trip (RTT) to the server.
- TLS handshake for HTTPS. Another one or two round trips depending on the protocol version.
- Sending the request (write). Headers and body are written to the socket. Instant for small requests, noticeable for file uploads.
- Waiting for the first byte of the response (TTFB). The server is thinking: running database queries, rendering the page, calling its microservices.
- Reading the response body (read). Data arrives in chunks; there are pauses between chunks.
What a Proxy Adds
A proxy splits this chain into two parts. The client establishes a connection with the proxy server, and the proxy itself establishes a connection with the target host. For HTTPS through an HTTP proxy, the CONNECT method is used: the client asks the proxy to open a TCP tunnel to the host and port, the proxy responds with status 200, and only then does the client begin the TLS handshake with the target server through the tunnel. For SOCKS5 the logic is similar: there's a greeting and authentication phase with the proxy, then a command to establish a connection with the target, then waiting for confirmation.
So we get an extended list of phases:
- DNS resolution of the proxy address (if it's specified as a domain).
- TCP connection to the proxy.
- Authentication and the command to establish a tunnel (CONNECT or SOCKS request).
- Waiting for the proxy to resolve the target hostname and establish a TCP connection with it — this phase happens on the proxy side, but the client is waiting for it.
- TLS handshake with the target server through the tunnel.
- Sending the HTTP request.
- Waiting for the first byte of the response.
- Reading the body.
Pay attention to the fourth point. This is where the main trap of mobile proxies lies. The proxy server itself usually sits in a data center, and the TCP connection to it is established in tens of milliseconds. But from there, traffic goes through a cellular modem, where RTT is 40–120 milliseconds and can spike to half a second or more when the cell tower is overloaded. Resolving the name and handshaking with the target on that segment can easily take one or two seconds. A client that only considers the "connect timeout" to the proxy will be certain the connection was established instantly, and then run into an inexplicable wait on the next step.
Deep Dive: What Physically Happens When Each Timeout Fires
Setting a number is only half the battle. Far more important is understanding what state the system is left in after a limit fires. Let's go through each phase.
When Connect Timeout Fires
The client sent a SYN and didn't get a SYN-ACK within the allotted time. The operating system itself repeats the SYN on an exponential schedule: 1, 2, 4, 8 seconds and so on, totaling up to 60–120 seconds by default in popular kernels. Your connect timeout interrupts that wait sooner. The socket is closed, no data went to the server, and nothing changed on the remote side. This is the safest kind of timeout: you can retry such an attempt without worrying about idempotency.
Through a proxy, the picture is a bit more complex. If TCP to the proxy is established but the CONNECT phase is stuck, the client has already sent the proxy a command and is waiting for a status. When the timeout fires, the client closes the socket to the proxy. The proxy will notice the closure and, as a rule, will abort its attempt to connect to the target. But not always instantly: some implementations first wait for their own upstream timeout and only then free up resources. This is invisible to the client, but on the proxy server, half-open connections accumulate, which under heavy load reduces its throughput.
An important nuance: different client libraries account for the CONNECT phase differently. In some, it falls under connect timeout; in others, it isn't covered by anything except the overall request deadline. If you don't have an overall deadline and CONNECT hangs, the request can hang indefinitely. It's easy to check: point your client at a proxy that accepts TCP but doesn't respond to CONNECT (a regular TCP server without logic can serve as such a stub) and see how many seconds it takes the client to give up.
When TLS Handshake Timeout Fires
The TCP tunnel through the proxy is open, the client has sent a ClientHello, and no ServerHello has arrived. Causes: slow modem channel, packet loss on the mobile segment, an overloaded target server that accepts TCP but is slow to process TLS. When the timeout fires, the socket is closed, the HTTP request hasn't been sent yet, and nothing has changed on the server. Also safe to retry.
A practical observation: over mobile channels, the TLS handshake is a frequent point of delay because it requires several consecutive round trips, and each lost packet adds a second for retransmission. Moving to TLS 1.3 reduced the number of round trips, which noticeably cut the share of such timeouts.
When Write Timeout Fires
The client is writing the request body to the socket, but the send buffer is full and not being drained: the remote side isn't reading or isn't acknowledging receipt. When the timeout fires, some data may already have reached the server. If it's a file upload or form submission, the server may have received a fragment. Usually an incomplete body causes a parsing error on the server side, but for streaming protocols and multipart uploads, the consequences depend on the implementation. Retrying such a request requires caution.
When Read Timeout Fires
This is where things get most interesting and most dangerous. The request has been sent in full. The client is waiting for data, and it doesn't arrive within the allotted interval. The client closes the socket and throws an exception. But what's happening on the other end?
The proxy sees that the client closed the connection. A good proxy will at that point close the upstream connection to the target server too. But the target server already received the request and is already processing it. If it's a POST that creates an order, debits a balance, or sends a message, the action will most likely be performed. The server will only learn about the disconnect when it tries to write the response and gets an error. By that point, the database transaction was long since committed.
This is a fundamental property of read timeout: it tells you that you didn't get a response, but says nothing about whether the action was performed. That's precisely why read timeout must be handled differently from connect timeout for non-idempotent operations, and precisely why serious APIs require idempotency keys.
Another nuance is where exactly you got stuck. Read timeout fires both while waiting for the first byte (server thinking) and during a pause between chunks of the body (server streaming data with delays). Many libraries treat read timeout as the idle interval between two successful reads from the socket, not as the total read time. This means a response hundreds of megabytes in size arriving at one kilobyte per second will never trigger a 10-second read timeout — data is arriving regularly. Without an overall deadline, such a request can hang for hours.
What the Proxy Sees and What It Returns
The proxy has its own timeouts, and they produce different symptoms. If the proxy couldn't connect to the target within its own limit, it returns a response to the CONNECT with status 502 or 504 — and from the client's perspective, that's not a timeout but a proxy error. If the proxy waited for a response from the target and didn't get one, it can also return a 504 Gateway Timeout inside the HTTP response (for plain HTTP without a tunnel). And if the proxy has an idle limit on the tunnel that fires, the client will see an abrupt connection drop — a connection reset or an empty response — with no timeout on its own side at all.
Hence the rule: the client timeout must be aligned with the proxy timeouts. If the proxy drops a tunnel after 60 seconds of inactivity and your read timeout is 90 seconds, you'll never see a timeout — you'll see mysterious disconnects. If the proxy allows 30 seconds to connect to the target and your limit for that phase is 10 seconds, you'll give up earlier and never learn that the proxy might have made it.
Method 1: Setting Connect Timeout with Two Hops in Mind
Theory: What It Covers and What It Should Cover
Connect timeout limits establishing the transport connection. Through a proxy, this raises the question: a connection to whom? Formally, to the proxy. In practice, what matters to us is when we get a ready tunnel to the target. So we recommend thinking in terms of two separate limits, even if the library gives you one parameter.
The first-hop limit is TCP to the proxy server. The proxy sits in a data center, RTT to it is stable. Benchmark: 5–8 RTT, but no less than 2 seconds and no more than 5. If the proxy doesn't respond to SYN within 3 seconds, it's either overloaded or unreachable, and waiting any longer is pointless; better to switch to another address in the pool.
The second-hop limit is the time from sending CONNECT to receiving status 200. This is where the mobile channel comes into play. The benchmark depends on where the target is located and the quality of the cellular network: typically 3–10 seconds. We've observed that the 95th percentile of tunnel establishment time through LTE to popular sites falls within 1.5–2.5 seconds, and the 99th within 4–6 seconds. Setting a limit below the 99th percentile means losing every hundredth request on your own initiative.
How to Measure Your Own Values
- Collect a sample of at least 500 requests through your proxy to the target hosts at different times of day.
- Log separately the time to establish TCP with the proxy, the time to the CONNECT response, and the TLS handshake time. Most clients can provide such metrics: in curl these are the time_connect and time_appconnect variables, in Go there are httptrace hooks, and in Python clients there are trace events or measurements around the phases.
- Build the distribution. You care about p50, p95, p99, and the maximum.
- Set the limit at p99 plus a 30–50 percent margin. Not at the maximum — outliers always exist, and accommodating them means holding resources for rare anomalies.
- Revisit quarterly or whenever the carrier, region, or proxy plan changes.
Practice in Different Clients
In the Python requests library, timeout is specified as a tuple where the first value is connect and the second is read. Through a proxy, the first value covers TCP to the proxy and, as a rule, waiting for the CONNECT response, since the tunnel is established on the same socket with the same limit. Example:
resp = session.get(url, proxies=proxies, timeout=(5, 20))In httpx there's a separate Timeout object with four fields: connect, read, write, and pool. This is the clearest model among Python clients:
timeout = httpx.Timeout(connect=5.0, read=20.0, write=10.0, pool=3.0)In curl there are two key flags: --connect-timeout sets the connection establishment limit, including CONNECT and TLS, and --max-time is the overall ceiling. In Go, the TCP dial timeout is set via Dialer in Transport, TLS via TLSHandshakeTimeout, and the CONNECT phase is bounded by the request context. In Java HttpClient, connectTimeout is configured on the client builder, and the request limit on the request itself. In Node.js via undici there's connectTimeout, headersTimeout, and bodyTimeout, plus AbortSignal for the overall deadline.
Connect Timeout Checklist
- The value is no less than 2 and no more than 10 seconds for a data-center or mobile proxy respectively.
- You know for certain whether your client covers the CONNECT phase with this limit.
- When it fires, you switch to another proxy from the pool rather than hammering the same one.
- You've accounted for the OS retrying SYN itself — your limit should be shorter than the system one.
- For IPv6 hosts, fallback to IPv4 (Happy Eyeballs) is enabled, otherwise a failed IPv6 path will eat the entire limit.
Method 2: Read Timeout as an Idle Interval and Protecting the First Byte
Two Different Jobs Under One Name
Read timeout solves two problems, and it's useful to keep them mentally separate, even if the library gives you one parameter.
Waiting for the first byte. This is the time the server spends working on your request. For static pages — tens of milliseconds. For a marketplace search page with filters — from half a second to several seconds. For heavy reporting APIs — tens of seconds. Through a mobile proxy, channel latency on the return path adds to this.
The pause between body chunks. The server is already sending data, but with interruptions: generating the page in pieces, streaming the result, or just hitting a narrow channel. What matters here isn't the total size but the maximum silence.
Some clients have separate parameters. In Go it's ResponseHeaderTimeout for the first byte of headers and separate mechanisms for the body. In undici — headersTimeout and bodyTimeout. In most Python clients, a single read timeout works as an idle interval at any stage of reading.
How to Choose the Value
- Determine the nature of the target responses. An HTML page and a streaming JSON require different limits.
- Measure TTFB through your proxy. Take p99 and multiply by 1.5. For typical web scraping through a mobile channel, that comes out to 8–15 seconds.
- Measure the maximum pause between chunks on a sample of successful responses. It's usually several times smaller than TTFB: 1–3 seconds. If your client allows it, set bodyTimeout separately and more tightly.
- Never rely on read timeout as protection against slow delivery. That's what the overall deadline is for (Method 4).
What to Do When It Fires
This is where the big question arises: can you retry? The answer depends on the method and semantics:
- GET, HEAD, OPTIONS — safe to retry; server state didn't change (unless the site violates protocol semantics).
- PUT with a full body, DELETE — formally idempotent, retry is safe.
- POST without an idempotency key — a retry may create a duplicate. The right reaction: don't blindly retry, but first check the state with another request or mark the operation as "unknown result" for later reconciliation.
- POST with an idempotency key — safe to retry; the server will return the result of the first execution.
We strongly recommend distinguishing in logs and metrics between read timeout before the first byte and read timeout in the middle of the body. The first more often points to target server or proxy overload; the second to channel problems. They're treated differently: in the first case, reducing concurrency helps; in the second, switching proxies or regions.
The Mobile Channel Specifics
Cellular networks operate with variable latency. A modem can "freeze" for a second or two when switching between cell tower sectors or when coming out of power-saving mode. From the client's perspective, this looks like silence on the socket. If your read timeout is 2 seconds, you'll catch false positives several times an hour on every modem. We've observed that raising the limit from 3 to 6 seconds cut the share of timeouts on mobile proxies by 4–5 times with no noticeable increase in average request time. Seconds of idling on rare requests cost less than retries and wasted traffic.
Read Timeout Checklist
- The value is based on measured p99 TTFB through your proxy, not intuition.
- You understand that the limit is an idle interval, not the total read time.
- For non-idempotent requests, there's no automatic retry on firing without verification.
- Metrics separate timeouts before the first byte from those inside the body.
- The value is less than the tunnel idle timeout on the proxy side.
Method 3: Write Timeout and Handling Large Request Bodies
When Writing Can Actually Hang
For most requests, the body fits in a single TCP segment and goes out instantly — the write completes before the data has physically left the machine. Write timeout becomes significant in three cases: file uploads, sending large JSON arrays, and any transfer over a narrow channel. A mobile proxy is exactly such a channel in the outbound direction: typical upload speed from a modem is noticeably lower than download speed, and buffers at intermediate nodes are limited.
The mechanics are as follows: the client calls write, the data lands in the socket send buffer, and the kernel sends it in chunks as acknowledgments come in. If acknowledgments don't arrive, the buffer fills up, and the next write blocks. Write timeout limits the time of such a block.
Three Strategies for Large Bodies
Strategy A: overall write limit. A simple approach: one write timeout for the entire request. Suitable for bodies up to a few megabytes. The value is chosen from an estimate: body size divided by the minimum acceptable speed, plus a margin. For example, 5 megabytes at a minimum speed of 500 kilobytes per second — 10 seconds, with a margin — 15.
Strategy B: per-chunk limit. The client writes the body in chunks and limits the time of each write. This is how most async clients work: write timeout there means the maximum pause when sending one chunk. The value is 3–10 seconds, regardless of file size. Protection against slow delivery as a whole falls to the overall deadline.
Strategy C: speed control. The client tracks the actual upload speed and aborts the request if it drops below a threshold for N seconds. In curl there's a pair of flags for this, --speed-limit and --speed-time. This is the most precise tool: it distinguishes "slow but moving" from "stuck."
What Happens When It Fires
Part of the body is already on the server. If you were uploading a file in a single request, the server will receive a truncated body. For the multipart protocol, this most often leads to a parsing error and a complete rejection, which is safe. For APIs with resumable upload support (tus, chunked cloud storage protocols), the right reaction is to ask the server for the offset and continue from there. We specifically recommend resumable uploads for any bodies over 10 megabytes through mobile proxies: a single long request over a cellular channel is too vulnerable to drops.
Step-by-Step Setup for Uploads Through a Proxy
- Estimate the median and minimum upload speed through your proxy. Upload a 5–10 megabyte test file twenty times at different times.
- If the speed spread is more than threefold, use Strategy B or C, not an overall limit.
- Break large files into 1–5 megabyte parts if the target service supports it.
- Set write timeout per chunk to 5–10 seconds.
- Be sure to supplement with an overall deadline for the entire request, calculated from size and minimum speed.
- When it fires — determine what exactly the server managed to receive rather than retrying everything from scratch.
Method 4: The Overall Request Budget and Deadline Propagation
Why the Sum of Individual Limits Isn't a Budget Yet
Suppose you set connect 5, TLS 5, write 10, read 15 seconds. It seems the request can't last more than 35 seconds. But read timeout is an idle interval. A response arriving at one kilobyte every 14 seconds will never violate it. A 10-megabyte request at that rate will take almost a day. Without an overall limit, your workers will be occupied indefinitely, the connection pool will be exhausted, and the system will grind to a halt — even though no individual timeout fired.
The overall budget (deadline, total timeout) is an absolute ceiling for the entire operation from the first system call to the last byte read. It doesn't replace individual limits; it complements them: individual limits give fast and precise diagnostics, while the overall one guarantees completion.
How to Calculate the Budget
Go top-down, not bottom-up. Start with the question: what's the maximum acceptable wait time for a single result for the business task? For an interactive scenario (a user is waiting) — 3–10 seconds. For background scraping — 30–60 seconds. For large file uploads — calculated from size.
Then this budget is distributed across phases based on measured distributions:
- Establishing the tunnel through the proxy (TCP plus CONNECT plus TLS): typically 15–25 percent of the budget.
- Writing the request: 5–10 percent for ordinary requests.
- Waiting for the first byte: 30–40 percent.
- Reading the body: the remainder.
Example: a 30-second budget for scraping through a mobile proxy. Connect (including CONNECT) 6 seconds, TLS 4 seconds, write 3 seconds, read as an idle interval 10 seconds, overall deadline 30 seconds. The sum of individual limits is 23 seconds, less than the budget — that's normal; they fire individually. The overall deadline catches cases of slow delivery that no individual limit will catch.
Propagating the Deadline Through the Chain
In distributed systems, a request is rarely a one-off. Your service received a task with a 30-second limit, spent 4 seconds on preparation, then goes through a proxy to the target site. How much time does the HTTP request have? Not 30, but 26 seconds minus a margin for processing the response. This is deadline propagation: each subsequent call gets not a fixed timeout but the remainder of the budget.
In Go this is implemented with a context with a deadline that's passed to the request. In Python — via asyncio with explicit passing of the remaining time. In Java — by computing Duration before each call. The rule is one: the HTTP request timeout is computed dynamically, as the minimum of the static limit and the remaining budget.
Without this, you get the classic problem: the upper layer has already given up waiting and returned an error, while the lower layer is still holding a connection through the proxy for another ten seconds and consuming traffic for a result nobody needs. With paid mobile proxy traffic, that's literally burning money.
The Connection Pool and Its Own Timeouts
Two more limits that are often forgotten. Pool timeout — how long to wait for a free connection from the pool if all are busy. If it isn't set, under a load spike, requests will wait indefinitely, and externally it looks like the client hanging. Set it to 1–3 seconds: if a connection doesn't free up within that time, the system is overloaded and it's better to fail fast.
Idle timeout of a connection in the pool — how long an unused keep-alive connection is stored before being closed. Here alignment with the proxy is critical. If the proxy closes idle connections after 60 seconds and your pool stores them for 90 seconds, then at the 61st second you'll pull a dead socket from the pool, send a request into it, and get a connection reset — not a timeout but a drop. Many libraries transparently retry the request in that situation, but only for idempotent methods. The rule: the client's idle timeout must be strictly less than the proxy's idle timeout, with a margin of at least 10–20 percent.
The Top-Down Budget Framework
- Fix the business constraint on the wait time for a result.
- Subtract the time for your own processing and the margin for a retry, if one is planned.
- The resulting remainder is the overall HTTP request deadline.
- Distribute it across phases according to the measured p99 of each phase through your proxy.
- Verify that each individual limit is less than the corresponding limit on the proxy side.
- Set the pool timeout and pool idle timeout in alignment with the proxy.
- Implement passing the remaining budget into nested calls.
- Log which limit fired and the time spent on each phase.
Method 5: Timeout Observability and Adaptive Tuning
No Measurement, No Tuning
All the previous methods come down to one thing: you need to know the real time distributions by phase through your proxy. The only way to know is to measure continuously. Modern clients provide trace hooks: the moment DNS starts, TCP is established, the CONNECT response is received, TLS completes, the request is sent, the first byte, the last byte. Collect these events into metrics broken down by proxy, target host, and error type.
Which Metrics to Collect
- Histograms of each phase's duration, separately by proxy endpoint and carrier.
- The share of each timeout type in the total number of requests.
- The share of timeouts before the first byte versus inside the body.
- The share of connection drops without a timeout (a sign of misaligned idle limits).
- The average time spent on requests that ended in a timeout — this is your direct loss in traffic and resources.
Adaptive Timeouts
The trend of recent years, which by 2026 has become the standard in mature systems, is adaptive limits. Instead of a static number, the client maintains a sliding window of observations for each proxy-target pair and sets the timeout as the p99 of the window with a margin factor, bounded above and below by reasonable bounds. When the channel degrades, the limit grows and false positives become fewer. When the channel recovers, the limit decreases and the system reacts faster to real problems.
The implementation is straightforward: a ring buffer of 200–500 recent measurements per key, recomputing the quantile every few seconds, bounds like "no less than 3 and no more than 20 seconds for read." It's important to protect against degradation: if all requests start timing out, the window fills with values at the limit level, and the limit will only grow. So only successful requests go into the window, and the limit's growth is capped by the upper bound.
Hedged Requests
For reads across a pool of several proxies, there's a technique that reduces the impact of slow tails without increasing timeouts: if a request hasn't completed within p95 time, send a duplicate through another proxy and take the first response to arrive. This increases traffic by a few percent but radically reduces p99 latency. It's suitable only for idempotent requests and requires careful cancellation of the losing duplicate so traffic isn't wasted.
Common Mistakes: What Not to Do
One Number for Everything
The most common mistake. A single 30-second timeout means you'll spend half a minute detecting a dead proxy, and you'll never detect a slow response in the middle of the body. Separate the phases.
No Default Timeouts
Several popular libraries have no timeouts out of the box: a request can hang indefinitely. In requests this is still the case. Any call without an explicit timeout through a proxy is a potentially forever-blocked worker.
Read Timeout Longer Than the Proxy's Idle Limit
You won't see timeouts; you'll see connection drops and look for the problem in the wrong place. Find out your proxy provider's limits and configure the client strictly below them.
Blind Retry After Read Timeout on POST
A direct path to duplicate orders, double charges, and repeated messages. After a read timeout on a non-idempotent request, the result is unknown — it needs to be investigated, not guessed at.
Ignoring the CONNECT Phase
Assuming that connect timeout covers tunnel establishment without verifying it in the specific library's docs. In some clients, the CONNECT phase hangs until the overall deadline, and if there is none — indefinitely.
Tuning to the Maximum
You saw one request take 45 seconds — so you set the limit to 60. Now every real problem costs you a minute of waiting. Aim for p99 with a margin, and hand outliers to the retry or hedging mechanism.
Timeout Without Cancelling the Underlying Work
The upper layer threw an exception by its own limit, but the HTTP request keeps living in a background task. This is an especially common mistake in async code: the wrapper with the wait has completed, but the coroutine hasn't been cancelled. Make sure a timeout firing leads to an actual socket close.
Identical Limits for Data-Center and Mobile Proxies
The difference in latency and jitter between them is multiple-fold. A profile that works on a server proxy produces a barrage of false timeouts on a mobile one. Keep separate configuration profiles.
No Pool Timeout
Under a load spike, requests wait indefinitely for a free connection. Externally — the entire client hangs with zero network traffic.
Tools and Resources
Command-Line Diagnostics
curl remains the reference tool for phase-by-phase analysis. The flags --connect-timeout, --max-time, --speed-limit, --speed-time cover all levels, and the -w output format with time variables shows how long each phase took:
curl -x http://user:pass@proxy:port --connect-timeout 5 --max-time 30 -o /dev/null -s -w "dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total}" https://example.com/Note: through a proxy, the time_connect variable shows the time to the proxy, and time_appconnect shows the time to TLS completion with the target, meaning it includes CONNECT. The difference between them is your second hop.
Client Libraries and Their Timeout Models
- Python requests: a tuple (connect, read). No write and no overall timeout; the overall is implemented via an external wrapper or thread-level cancellation.
- Python httpx: a Timeout object with connect, read, write, pool. No overall, but in async mode it's easily added via a wait with a limit and cancellation.
- Python aiohttp: ClientTimeout with total, connect, sock_connect, sock_read fields. The only one of the popular Python clients with a built-in overall limit.
- Go net/http: Dialer.Timeout, TLSHandshakeTimeout, ResponseHeaderTimeout, ExpectContinueTimeout, IdleConnTimeout on the transport; Client.Timeout as the overall; the request context as a dynamic deadline.
- Java HttpClient: connectTimeout on the client, timeout on the request (covers up to receiving headers). Body reading is bounded at the BodyHandler level or via a wrapper.
- Node.js undici: connectTimeout, headersTimeout, bodyTimeout, keepAliveTimeout; the overall — via AbortSignal.timeout.
Traffic Analysis
tcpdump and Wireshark let you see what actually happened on the wire: did the SYN go out, did the SYN-ACK come back, who sent FIN or RST first. This is the only way to reliably answer the question "who dropped the connection — me, the proxy, or the server." For HTTPS content, visibility is limited, but the connection and tunnel phases are fully visible.
Test Benches for Reproduction
To test client behavior during hangs, it's useful to have a set of stubs: a TCP server that accepts a connection and stays silent (tests connect and CONNECT); an HTTP server that responds with headers and then stays silent (tests read up to the body); a server that sends one byte per second (tests the overall deadline). Writing such stubs is half an hour of work, and the time saved on production debugging is measured in days. There are also network emulation tools that let you add latency, jitter, and loss on an interface to simulate a mobile channel in the lab.
Observability
Collecting metrics and traces in OpenTelemetry format with automatic HTTP client instrumentation has become the standard. Histograms by phase and attributes with the proxy ID and the type of limit that fired are the minimum set without which tuning becomes guesswork.
Case Studies and Results
Case 1: Marketplace Scraping Through Mobile Proxies
A team was collecting product cards through a pool of mobile proxies. Initial configuration: a single 15-second timeout, no overall deadline, a standard connection pool. Symptoms: 11 percent of requests ended in errors, of which two-thirds were timeouts and one-third connection drops. The average duration of a failed request was 14 seconds, meaning every tenth request wasted time and traffic for nothing.
Phase-by-phase diagnostics showed: p99 tunnel establishment — 4.8 seconds, p99 TTFB — 6.2 seconds, the maximum pause between chunks on successful responses — 2.1 seconds, the provider's tunnel idle limit — 60 seconds, and the client's pool stored connections for 120 seconds.
Changes: connect 7 seconds with CONNECT coverage, read 9 seconds, write 5 seconds, overall deadline 25 seconds, pool idle 45 seconds, pool timeout 2 seconds. Separating timeouts before the first byte from those inside the body in the metrics.
Result after a week: the overall error rate dropped to 3.4 percent, connection drops essentially disappeared, and the average duration of a failed request fell to 8 seconds. Traffic consumption per unit of data collected dropped by 19 percent. No changes were made to the retry logic — only timeouts.
Case 2: Payment API Integration and Duplicates
A service was sending POST requests to create payment operations through a corporate proxy. Read timeout of 10 seconds and automatic retry on any exception. Every few days, duplicate operations appeared. Analysis showed: the target API under load responded in 11–14 seconds, the client dropped out on read timeout, retried the request, and both operations succeeded.
The solution had three parts: read timeout raised to 20 seconds based on a measured p99 of 15 seconds; retry after read timeout on POST replaced with a status query by client identifier; and an idempotency key added in the header, which the API supported. Duplicates stopped completely. The team's separate takeaway: read timeout on a non-idempotent request is not an error but a state of "result unknown" requiring its own handling branch.
Case 3: Media File Uploads Through a Mobile Channel
An application was uploading videos of 50–200 megabytes through mobile proxies in a single request. Write timeout of 30 seconds, no overall deadline. Symptoms: about 8 percent of uploads failed, each failure meant restarting from scratch, and daily traffic overage reached tens of gigabytes.
The switch went to chunked uploads of 4 megabytes with resumption, a write timeout per chunk of 8 seconds, a minimum speed check of 100 kilobytes per second for 10 seconds, and an overall deadline per chunk of 60 seconds. The share of fully failed uploads fell to 0.3 percent, and traffic overage for retries dropped 12-fold because only the last failed chunk was retried.
Case 4: CONNECT Hanging Without an Overall Deadline
An async collector on one of the Python libraries periodically "froze": workers alive, network silent, queue not moving. After an hour or two, the collector was restarted manually. The investigation showed: some proxies in the pool accepted TCP but didn't respond to CONNECT. In the configuration used, this phase wasn't covered by any limit. Adding an overall deadline for the entire request and an explicit limit for tunnel establishment eliminated the freezes. Additionally, a proxy healthcheck was added that checks the CONNECT phase specifically, not just TCP reachability.
FAQ: Tricky Questions About Timeouts Through a Proxy
How does a client timeout differ from a 504 response from the proxy?
A client timeout is your decision to stop waiting; the proxy and server only learn about it from the socket closing. A 504 response is the proxy's decision: it itself didn't wait for the target server and informed you with a full HTTP response. In the first case, the socket closes with an exception; in the second, you get a normal response with an error code. They need to be handled differently: 504 means the proxy is definitely alive and the problem is further down the chain; a client timeout says nothing about where exactly you got stuck.
Why are longer timeouts needed through a mobile proxy than through a data-center one?
Because of jitter. The average latency of a cellular channel isn't that high, but its spread is huge: switches between cell sectors, modem power-saving modes, contention for radio resources. A timeout is tuned to the tail of the distribution, and the tail of a mobile channel is several times longer. At the same time, overly long limits are also harmful — they slow down detection of genuinely dead proxies. The balance is achieved by measuring p99 plus a 30–50 percent margin, not by doubling all the numbers.
How do you tell which timeout fired if the library throws a single generic exception?
Three ways. First, by time: if the exception arrived after a duration equal to the connect timeout rather than the read one, you know the phase. Second, via trace hooks: if the "TLS completed" event happened but "first byte" didn't, you got stuck on TTFB. Third, by the text and type of the exception: many libraries distinguish ConnectTimeout and ReadTimeout as separate classes. We recommend always logging which phases completed before the exception — this turns a mysterious timeout into a precise diagnosis.
Can you retry a request after a write timeout fires?
For GET with no body — yes, nothing went out. For POST with a body — only if you're sure the server rejects incomplete bodies. Most servers do: incomplete JSON or truncated multipart causes a parsing error. But streaming APIs that begin processing as data arrives may partially apply changes. If in doubt, verify state before retrying.
How do you align client timeouts with proxy provider timeouts?
Ask the provider or find three values in the docs: the limit for connecting to the target host, the tunnel idle limit, and the maximum connection lifetime. Your tunnel establishment limit should be no less than the provider's (otherwise you give up before the proxy could have made it), and your read timeout and pool idle must be strictly less than the provider's idle limits. If there's no documentation, measure empirically: open a connection, stay silent for N seconds, try to send a request, find the threshold after which a drop occurs.
Do you need an overall deadline if all individual limits are set?
Yes, absolutely. Individual limits don't bound the total time: slow body delivery at one kilobyte with intervals shorter than the read timeout can last indefinitely. The overall deadline is the only guarantee that the worker frees up. Also, when propagating the budget through a call chain, it's the overall deadline that's passed down, while individual limits remain local configuration.
How do HTTP/2 and HTTP/3 affect the timeout model through a proxy?
HTTP/2 multiplexes many requests over one connection, so socket-level read timeout stops being a single request's timeout: the socket receives data from other streams, and a specific request's idleness goes unnoticed. You need stream-level limits — most HTTP/2 clients provide them via the request deadline. HTTP/3 over QUIC also changes the connection phase: the handshake is combined with the cryptographic one, and connect timeout covers both. Through a classic CONNECT proxy, HTTP/3 to the target generally doesn't get through — the tunnel is TCP-oriented, and the client falls back to HTTP/2 or HTTP/1.1. Extensions for UDP tunneling through proxies are developing, but as of 2026 their support in mainstream clients is limited.
What should you do if, after a timeout, the connection returns to the pool and the next request fails?
This is a sign that the client didn't close the socket properly or the pool didn't mark the connection as broken. A connection on which read timeout fired can't be reused: it may contain bytes of a late response that will be read as the answer to the next request. Make sure your client closes the connection on timeout rather than returning it to the pool. In well-designed clients, this is the default behavior, but with custom wrappers and low-level socket work, the mistake occurs regularly.
How do you set timeouts for a SOCKS5 proxy as opposed to an HTTP proxy?
The principle is the same; the phases differ: instead of CONNECT there's a greeting, authentication, and a connect command, which is two or three round trips to the proxy plus the time for the proxy to connect to the target. In most clients, the entire SOCKS handshake falls under connect timeout. Make sure the value accounts not only for TCP to the proxy but also for the time to establish the proxy's connection to the target through the mobile channel — the same 3–10 seconds.
Conclusion: Timeouts as an Engineering Discipline
Let's sum up. An HTTP request through a proxy is not a single operation but a chain of seven or eight waiting phases, each with its own nature of delays and its own consequences on a drop. Connect and TLS timeouts are safe: nothing went to the server, you can try again. Write timeout leaves the server with incomplete data. Read timeout is the most insidious: the request was delivered and possibly executed, and you don't know it. The overall deadline doesn't replace individual limits but protects against slow delivery that they don't catch.
Through mobile proxies, all of this is amplified: the second hop goes over a channel with high jitter, and limits tuned on server proxies produce a barrage of false positives. The only way to set them correctly is to measure phase distributions through your specific proxy and set limits at p99 with a margin, aligning them with the proxy's own limits.
Your next steps:
- Find every HTTP call through a proxy in your code and check whether it has explicit timeouts for all phases and an overall deadline.
- Determine whether your client covers the CONNECT phase and how it treats read timeout — as idleness or as total time.
- Find out your proxy provider's idle limits and connection limits and bring the client settings into alignment.
- Enable phase tracing and collect distributions for a week.
- Recalculate limits at p99 and split profiles for data-center and mobile proxies.
- Separate timeout handling for idempotent and non-idempotent requests.
- Add to metrics the type of limit that fired and the phase on which it fired.
Timeouts aren't a parameter you set once and forget. They're part of your system's contract with the outside world, and like any contract, they require measurement, revision, and agreement between the parties. Do this once systematically — and you'll be surprised how much quieter your logs get and how much cheaper your traffic becomes.