Errors / checked October 9, 2026

curl: (7) Failed to connect to api.example.com port 443 after 21 ms: Couldn't connect to server

The error

Output of a curl call when the host name resolved but nothing accepted the connection on that port, common in cron jobs that call an API or webhook.

Quick fix

  1. Check the port and scheme: https uses 443, http uses 80. A URL with the wrong one (or a local port like 3000) fails this way.
  2. Check that the service is running and listening: from the server itself, curl it on localhost; from outside, make sure a firewall or security group allows the port.
  3. If it fails only sometimes, the server is restarting or overloaded: retry with --retry 3 --retry-connrefused.

Why this happens

Exit code 7 means curl failed to connect to the host: the name resolved, but the connection was refused or never answered. The "after N ms" part tells you how quickly it failed; a very short time usually means the port is closed.

Source: curl man page: exit codes

Other solutions

  • Calling a service that only listens on 127.0.0.1 from another machine fails with this error.
  • For scheduled calls, a hosted scheduler that retries keeps a deploy or restart from becoming a missed run. RunLater retries failed calls with exponential backoff, up to 10 times, and logs each attempt.

Check a schedule before you deploy it: the cron expression explainer shows the next 10 run times.

Frequently asked questions

What does curl exit code 7 mean?

Failed to connect to host. The curl man page lists it as exit code 7: the address was found but the connection did not succeed.

Does --retry help with error 7?

Only with --retry-connrefused, or on newer curl --retry-all-errors; by default curl does not treat a refused connection as transient.

Have the URL called on schedule, with retries

RunLater calls your URL on a cron schedule or at an exact time, in your timezone, retries failed calls with backoff and logs each response, so a timeout or a 5xx shows up in a log instead of disappearing.

Start a 14-day trialStarter is $15/month for 250 scheduled requests and 25,000 runs. Cancel before day 14 and you pay nothing.

Related errors