Skip to content

curl error 28 through a proxy: find what timed out

curl exits with code 28 (CURLE_OPERATION_TIMEDOUT) when one of its own deadlines runs out: --connect-timeout while connecting, or --max-time for the whole transfer. Nothing was refused. Through a proxy the wait can be on the proxy host, the proxy's answer to CONNECT, the site's TLS handshake or the site's response, and the message together with %{http_connect} says which.

Reviewed by John Hale. Last updated .

What it looks like

curl 8.7.1, while connecting
curl: (28) Failed to connect to 192.0.2.1 port 8080 after 3011 ms: Timeout was reached
curl: (28) Connection timed out after 3011 milliseconds

curl 8.7.1, after the request was sent
curl: (28) Operation timed out after 3011 milliseconds with 0 bytes received
curl: (28) Operation timed out after 3009 milliseconds with 7 out of 1000 bytes received

Python requests and Node.js fetch, the same waits
requests.exceptions.ProxyError: ... ConnectTimeoutError(..., 'Connection to 192.0.2.1 timed out. (connect timeout=3)')
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='example.com', port=443): Read timed out. (read timeout=3)
TimeoutError: The operation was aborted due to timeout

What does curl error 28 mean?

libcurl documents CURLE_OPERATION_TIMEDOUT (28) as a time-out period that was reached. It is a limit on your side. curl has no default limit on a whole transfer, so Operation timed out means a --max-time (-m, or CURLOPT_TIMEOUT in a library) was set somewhere. Connecting does have a default limit of 300 seconds, which --connect-timeout replaces.

Through an HTTP proxy, connecting covers more than TCP. In our tests a proxy that accepted the connection and never answered CONNECT, and a tunnel that opened but whose TLS handshake with the site never finished, both printed Connection timed out. Operation timed out appeared only after the request itself had been sent.

What causes curl error 28 through a proxy?

Most likely first.

  1. The proxy host or port cannot be reached. Failed to connect to HOST port PORT after N ms: Timeout was reached. No TCP connection was made: a wrong host, a port your network filters, or a firewall that drops packets without answering. A closed port answers at once and exits 7, not 28.
  2. The proxy accepted the connection and did not answer. Connection timed out with %{http_connect} at 000. The proxy took the TCP connection and never replied to CONNECT: an overloaded proxy, or one still looking for an exit that matches your targeting.
  3. The site did not finish TLS inside the tunnel. Connection timed out with %{http_connect} at 200. The proxy opened the tunnel and the handshake with the site never completed. The route from that exit to the site is slow, or the site is ignoring that exit.
  4. The site was slow to answer. Operation timed out with 0 bytes received. The request went out and no response arrived before --max-time: a slow page, a site that stalls requests it does not want, or a deadline shorter than the page takes.
  5. The download stalled part way. Operation timed out with N out of M bytes received. The response started and stopped. Large files over residential exits hit this when the limit was sized for a datacenter line.
  6. A deadline that is too tight for a proxy. A proxy adds a hop, and a rotating exit adds the time to choose one. A 2 or 3 second limit that works on a direct connection can fail through a proxy with nothing wrong.

How do you find what timed out?

  1. Print where the time went

    CONNECT 000 means the proxy never answered. CONNECT 200 with site 000 means the tunnel opened and the site did not answer in time. time_connect is TCP to the proxy, time_appconnect ends when TLS with the site is done, and time_starttransfer is the first byte of the response.

    One line per request
    curl -s -o /dev/null -x http://HOST:PORT -U "USER:PASS" --connect-timeout 15 --max-time 60 \
      -w "CONNECT %{http_connect} | site %{http_code} | tcp %{time_connect}s | tls %{time_appconnect}s | first byte %{time_starttransfer}s | total %{time_total}s | exit %{exitcode}\n" \
      https://TARGET/

  2. Test the proxy and the site apart

    If the direct request is slow too, the site is slow. If example.com is fast through the proxy and your target is not, the delay is between the exit and that site.

    Direct, then a fast site through the proxy
    curl -sS -o /dev/null -w "direct: %{http_code} in %{time_total}s\n" --noproxy '*' --max-time 30 https://TARGET/
    curl -sS -o /dev/null -w "proxy: %{http_code} in %{time_total}s\n" -x http://HOST:PORT -U "USER:PASS" --max-time 30 https://example.com/

  3. Find the deadline that is set

    Look for -m, --max-time and --connect-timeout in the command and in ~/.curlrc, and for CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT in the code that wraps libcurl. PHP, Git and many SDKs print the same cURL error 28 with defaults of their own.

    Timeouts in ~/.curlrc
    grep -iE "max-time|connect-timeout|^-m" ~/.curlrc

How do you fix curl error 28?

  • Set both deadlines on purpose

    --connect-timeout covers reaching the proxy, the tunnel and TLS. --max-time covers everything. Size them for the slowest honest case, not the average one.

    Two limits
    curl --connect-timeout 15 --max-time 90 -x http://HOST:PORT -U "USER:PASS" https://TARGET/

  • Retry timeouts, with a pause

    curl treats a timeout as transient, so plain --retry covers error 28. Add a delay so a struggling site is not hit again at once, and cap the total with --retry-max-time.

    Three retries inside three minutes
    curl --retry 3 --retry-delay 2 --retry-max-time 180 --connect-timeout 15 --max-time 60 \
      -x http://HOST:PORT -U "USER:PASS" https://TARGET/

  • For large files, detect a stall instead

    --speed-limit and --speed-time end a transfer only when it stays under a rate for a while, so a slow download that is still moving is left alone.

    Abort under 1 KB/s for 30 seconds
    curl --speed-limit 1024 --speed-time 30 -x http://HOST:PORT -U "USER:PASS" -O https://TARGET/file.zip

  • When one route is slow, change the exit

    With a rotating proxy the next request leaves from another exit. With a sticky session, start a new session ID. If every exit is slow to one site and fast to others, the site is slowing that traffic, and a longer timeout only waits longer.

If you use TrueProxies

A timeout is never a login problem here: the gateway answers a refused login at once with 407 and a reason in X-Proxy-Reason.

When a site does not answer a plain http:// request through the exit in time, the gateway replies 503 Service Unavailable with the reason No response. The destination did not answer through this IP in time. Retry the request. For CONNECT, a destination that refused, reset or did not answer comes back as 503 without a reason, and a sticky session whose IP could not reach this one site gets 502 with a reason that says the session keeps its IP.

Those are HTTP answers you can read. If curl's own deadline is shorter than the gateway's wait for the destination, curl gives up first and you see error 28 instead, so keep --max-time generous while you debug:

The gateway's status and reason
curl -sS -o /dev/null -D - -x http://HOST:8080 -U "USER:PASS" --max-time 90 http://TARGET/ \
  | grep -iE "^HTTP/|x-proxy-reason"

An error 28 with CONNECT 200 means the tunnel is open and the wait is on the site's side of it.

Test the proxy from outside your network

The free proxy checker connects from our servers and reports the failed stage as a code, so you can tell a proxy problem from one on your computer or network.

Run the proxy checker

Questions about curl error 28

What does curl error 28 mean?

CURLE_OPERATION_TIMEDOUT: a time limit set with --connect-timeout or --max-time, or their library equivalents, ran out before curl finished. It is a deadline on your side, not a refusal from the proxy or the site.

What is the difference between Connection timed out and Operation timed out?

Connection timed out means the limit hit while curl was still connecting, which through a proxy includes the answer to CONNECT and the TLS handshake. Operation timed out means the request was sent and the response did not arrive, or did not finish, in time.

Is curl error 28 the proxy's fault?

Print %{http_connect}. 000 means the proxy did not answer the tunnel request. 200 means the proxy did its part and the site was slow through that exit.

Does curl --retry retry error 28?

Yes. Timeouts are among the errors curl treats as transient, so --retry covers them without --retry-all-errors.

What is curl's default timeout?

There is no default limit on the whole transfer. The connection phase has a default limit of 300 seconds, which --connect-timeout replaces.