Stop curl from timing out on hanging requests silently

Networking & Firewall (Ss/Netstat/Iptables/Curl)

Stop curl from timing out on hanging requests silently

🧩 The Challenge

Everyone has dealt with a script that just sits there spinning forever because the remote server decided to hang rather than close the connection. I spent three hours chasing a ghost process last month before I realized my curl command had no guardrails.

💡 The Fix

Throw a couple of time-based flags into your curl calls so the process actually dies if the server goes unresponsive. It keeps your automation from clogging up the server with orphaned handles.

curl --connect-timeout 10 --max-time 30 https://example.com/api/data

⚙️ Why It Works

Setting these limits forces curl to drop the connection if the handshake stalls or if the total transfer takes longer than your threshold. It prevents those zombie threads that usually pile up when you’re fetching data from unreliable third-party APIs.

🚀 Pro-Tip: Use the -v flag while you are testing the timeout so you can actually see exactly which stage is hanging.

Linux Tips & Tricks | © ngelinux.com | 8/6/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted