Glossary
Timeout: how long to wait before giving up
A timeout is the maximum time a client waits for something (a connection, a byte of response, a finished job) before it stops waiting and treats the attempt as failed.
Why every call needs one
Without a timeout, a request to a stalled server can wait for minutes or forever. In a scraper with a fixed pool of workers, a few hung connections can freeze the whole job while it looks healthy from the outside. Many popular HTTP clients, including Python Requests and Node's fetch, have no overall timeout unless you set one. Make setting it a habit.
The kinds of timeout
| Timeout | Measures | Typical value |
|---|---|---|
| Connect | Time to open the TCP (and TLS) connection | 3~10 seconds |
| Read | Longest gap between bytes received | 15~60 seconds |
| Write | Longest gap while sending the body | Rarely tuned except for uploads |
| Pool | Waiting for a free connection in the client pool | A few seconds |
| Total | The whole request end to end | Depends on the target |
A read timeout resets every time data arrives, so a server trickling one byte every few seconds can keep a request alive far longer than the read timeout suggests. A total deadline catches that case.
Setting them in common clients
# Python, httpx: separate connect and read limits
import httpx
limits = httpx.Timeout(connect=5.0, read=30.0, write=10.0, pool=5.0)
with httpx.Client(timeout=limits) as web:
page = web.get("https://example.com/catalog")
# Python, Requests: a (connect, read) tuple
# requests.get(url, timeout=(5, 30))
# JavaScript fetch: a total deadline through an abort signal
# await fetch(url, { signal: AbortSignal.timeout(30000) })
Task deadlines are different
With an asynchronous API, two clocks run. Each HTTP call to the API has its own short timeout, since createTask and getTaskResult answer quickly. The job behind them has a separate, longer deadline. On GateSolver, a task that is not solved within 120 seconds is marked failed and is not billed. Your client should keep its own overall deadline a little above that, say 130 seconds, so it never waits on a task the server has already given up on.
Most tasks finish far sooner: a Cloudflare Turnstile token typically under 3 seconds, an image text answer under 1 seconds. A sensible setup is a 10~20 second timeout on each API call, polling every 3 seconds for tokens (1 second for images), and an overall deadline per task.
Timeouts and tokens
Solved tokens also expire. A reCAPTCHA token is valid for about two minutes; Turnstile tokens have a similar short life. If your workflow solves a token and then spends a long time loading or filling the page, the token may expire before you submit. Solve as late as possible, right before the submit step.
After a timeout
Decide whether a retry is safe. Reads are safe to repeat; actions that create something may already have happened (see idempotency). Space retries with exponential backoff, and log which kind of timeout occurred: connect timeouts point to network or proxy trouble, read timeouts to a slow or throttling server.
Common questions
What is the difference between a connect and a read timeout?
Connect limits the time to open the connection; read limits the longest pause between bytes of the response.
Does Python Requests have a default timeout?
No. Without the timeout argument it can wait indefinitely, so always pass one.
How long does GateSolver wait before failing a task?
120 seconds. An unsolved task is then marked failed and costs nothing.
What overall deadline should my client use for a task?
Slightly above 120 seconds, for example 130, with short timeouts on each individual API call.
Can a solved token expire before I use it?
Yes. Tokens last about two minutes, so solve right before you submit.
Keep reading
- Asynchronous APIAPIs that accept a job now and deliver the result later, like createTask with getTaskResult, and how to poll them well.
- Exponential backoffRetrying with delays that double each time plus random jitter, the standard response to 429 and 5xx errors.
- How do I deal with 504 Gateway Timeout?A 504 means a gateway waited too long for the server behind it; retry later, lighten requests and check slow proxies.
- Task pollingAsking getTaskResult for an answer on a timer: sensible intervals for token and image tasks, and when to give up.