brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl speed-limit aborts a download that has stalled

Curl
~/tips/tip-curl-speed-limit-stalled

curl --speed-limit 1000 --speed-time 30 -O https://example.com/images/big.iso

Stop a transfer that crawls along at almost nothing, without capping the total time.

A download that hangs at a few bytes per second can sit there forever. --speed-limit and --speed-time make curl give up when it stays that slow for too long.

The two options work as a pair: a speed in bytes per second, and how many seconds the transfer may stay below it.

curl --speed-limit 1000 --speed-time 30 -O https://example.com/images/big.iso

If the download runs slower than 1000 bytes per second for 30 seconds in a row, curl aborts it with exit code 28. The short forms are -Y and -y. If you only set the time, the speed limit defaults to 1 byte per second, which catches a transfer that has completely frozen.

I prefer this over --max-time for big files. A maximum time has to be long enough for the slowest good download, so it does little against a stall. The speed check reacts to the stall itself and leaves a slow but working download alone.

It pairs well with retries: a script can run curl -C - --speed-limit 1000 --speed-time 30 again after exit code 28 and continue where it stopped. Keep in mind it only watches the transfer itself. A server that never answers the connection is a job for --connect-timeout.

Further reading: curl man page, curl exit codes

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link