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 --max-time keeps a hung request from blocking your script

Curl
~/tips/tip-curl-max-time-connect-timeout

curl --connect-timeout 5 --max-time 30 -fsS https://example.com/api

Aborts a request that takes too long to connect or to finish.

Without limits curl can sit on a dead connection for minutes.

curl --connect-timeout 5 --max-time 30 -fsS https://example.com/api

--connect-timeout only limits the connection phase, and --max-time caps the whole transfer including the download. When the limit hits, curl exits with code 28. For large files a total limit is awkward, so use --speed-limit 1000 --speed-time 20, which aborts if the speed stays under 1000 bytes per second for 20 seconds. With --retry the time limit starts again on every attempt, and --retry-max-time caps the total.

Further reading: curl manual

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