← Mac Change Notes

Why curl Outlasts connect-timeout

On a Mac, add --max-time to limit an entire curl transfer. --connect-timeout limits connection setup; once that succeeds, a slow response can continue beyond it.

In this article

For example, a server might accept the connection immediately and then take several seconds to produce its answer. A one-second connection limit does not give that server a one-second response deadline. Start by deciding which wait you want to bound.

Set both limits when checking one URL

The built-in command can express a short setup budget and a longer overall transfer budget:

/usr/bin/curl --connect-timeout 5 --max-time 20 https://example.com/

These are example limits, not recommended values for every service. A large download may legitimately need much longer. Replace the URL with the endpoint you intend to check, and choose a total limit that allows the expected response to finish.

SettingWhat it boundsWhat it does not promise
--connect-timeout 5Connection setupCompletion of the response within five seconds
--max-time 20One transfer attempt, including setupTwenty additional seconds after connecting
Both togetherEach limit applies to its own scopeA combined twenty-five-second allowance

curl's connection-timeout reference explicitly places connection time inside the overall transfer limit. If setup takes three seconds of a twenty-second transfer budget, it has already used those three seconds.

A successful connection can still leave you waiting

We tested Apple's /usr/bin/curl on macOS 15.7.5 on December 1, 2026. A disposable server listened only on 127.0.0.1, the Mac's loopback address. It deliberately delayed either the HTTP headers or part of the response body. There was no remote website, DNS delay, or internet congestion in these HTTP cases.

Each request used a 0.25-second connection limit. We disabled curl's default configuration for the test with -q as its first option and excluded proxies for this loopback target. Those controls made the comparison about the two timers rather than an existing configuration file or proxy.

Controlled server behaviorOverall limitObserved durationResult
Wait 1.5 seconds before sending headers and two body bytesNone set1.511 secondsHTTP 200; exit 0; two bytes received
Same delayed headers0.6 seconds0.612 secondsExit 28; no body received
Send HTTP 200 and one byte immediately, then delay the second byte0.6 seconds0.609 secondsHTTP 200; exit 28; only one byte received

The first request is the apparently surprising one: it ran for roughly six times the connection timeout and succeeded. Its connection had taken less than a millisecond. Waiting for the response happened afterward, so the connection limit had already done its job.

The other two requests show the role of the overall limit. Neither was allowed to wait for the full delayed response. Small timing differences around the requested deadline are observations from this test, not a precision guarantee.

These results demonstrate timer scope on this Mac and curl build. They do not measure another application's timeout policy or predict how long a production server should take.

TCP connected is not always connection setup finished

For HTTPS, establishing TCP is only part of setup. The relevant TLS handshake also needs to complete. curl's timeout guide includes name resolution and the required protocol handshakes in the connection phase.

We added a fourth controlled case: a loopback socket accepted TCP but deliberately never completed the TLS handshake. With --connect-timeout 0.25, curl stopped after 0.260 seconds, returning 28. Its recorded TCP connection time was under a millisecond; its TLS completion time remained zero.

No certificate check was disabled. The endpoint never progressed to a completed TLS handshake. This matters when interpreting “connected” in a log: a completed TCP connection alone does not establish that an HTTPS transfer has passed every setup step.

An immediate refusal is different again. A timeout is a maximum wait, not a minimum delay before reporting any failure. See connection refused versus timed out when the command fails sooner than the number you supplied.

Check completion separately from HTTP status

The partial-body test received HTTP 200 and still failed. That status arrived in the headers; it did not prove that the declared response body had arrived in full.

For a read-only diagnostic request, record timings and the exit status separately:

/usr/bin/curl --silent --show-error --output /dev/null --connect-timeout 5 --max-time 20 --write-out 'http=%{http_code} total=%{time_total}\n' https://example.com/

printf 'exit=%s\n' "$?"

Run the printf immediately after curl so $? still refers to that command. Here /dev/null deliberately discards the response body; use this for checking a request, not for saving a download. curl's command manual documents these output options and exit codes.

Keep the error text too. Exit 28 identifies a timeout, but that number alone does not tell you whether setup, waiting for headers, or receiving the body was responsible. A complete-looking status line is equally insufficient on its own.

Keep retries and other request behavior explicit

The examples above make one attempt. When --retry is enabled, the per-transfer maximum starts again for each retry; the overall command can consequently run longer. The max-time option documentation points to separate retry controls. Do not treat the single-attempt example as a deadline for a script containing retries or several URLs.

Also compare like requests. Following redirects changes which responses are fetched. A different proxy configuration can change the route to the server. Record those conditions before deciding that two measurements contradict each other.

Use this decision sequence: bound setup with --connect-timeout; bound one complete attempt with --max-time; check the exit status and received data; then investigate the phase that actually stalled. Increasing the connection limit will not fix a deadline you meant to apply after connecting.