3

I am running curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 and I am trying to set --max-time or --connect-timeout, unfortunately these values seem to do nothing.

PoC 1:

time curl -v -k -I --max-time 5 https://myawesomehost/file.test
* Resolving timed out after 5001 milliseconds
* Closing connection 0
curl: (28) Resolving timed out after 5001 milliseconds

real    0m10.031s
user    0m0.011s
sys 0m0.012s

This should have killed the command after 5 seconds but it took 10.031s

PoC 2:

time curl -v -k -I --connect-timeout 3.0 https://myawesomehost/file.test
* Resolving timed out after 3000 milliseconds
* Closing connection 0
curl: (28) Resolving timed out after 3000 milliseconds

real    0m10.068s
user    0m0.005s
sys 0m0.010s

Again, it took 10.068s.

I found that I can use timeout command-line tool but I would like to know what is the issue with curl.

1
  • Where did you get this copy of cURL? Based on @anthony-t's comment below, it sounds like something's screwy with the way it was built, but it would probably be good to hunt that to its source... May 13, 2020 at 21:23

1 Answer 1

3

Without seeing your curl --version let me take a stab in the dark based on just running into this exact problem. Is your version of curl built without c-ares? The first line of curl --version should tell you:

curl 7.71.0-DEV (x86_64-unknown-linux-gnu) libcurl/7.71.0-DEV c-ares/1.10.0

I recently ran into this same issue where DNS timeouts caused curl to exceed the specified timeouts. With verbose turned on it would show the DNS lookup DID timeout at 5 seconds, but then would wait until 20s to completely timeout and close. We root caused it to versions without c-ares (asynchronous DNS resolver library).

I built it from source taken from their github using these instructions but adding ./configure --enable-ares

Here you can see it built with c-ares c-ares/1.10.0 in the version info

$ /usr/local/bin/curl --version
curl 7.71.0-DEV (x86_64-unknown-linux-gnu) libcurl/7.71.0-DEV c-ares/1.10.0
Release-Date: [unreleased]
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
Features: AsynchDNS IPv6 Largefile UnixSockets

and it behaves as expected

$ time /usr/local/bin/curl --max-time 5 google.com -v
* Resolving timed out after 5000 milliseconds
* Closing connection 0
curl: (28) Resolving timed out after 5000 milliseconds

real    0m5.002s
user    0m0.000s
sys     0m0.002s

And built without c-ares

/usr/local/bin/curl --version
curl 7.71.0-DEV (x86_64-unknown-linux-gnu) libcurl/7.71.0-DEV
Release-Date: [unreleased]
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp 
Features: AsynchDNS IPv6 Largefile UnixSockets

Timeout doesn't work:

time /usr/local/bin/curl --max-time 5 google.com -v
* Resolving timed out after 5000 milliseconds
* Closing connection 0
curl: (28) Resolving timed out after 5000 milliseconds

real    0m20.023s
user    0m0.003s
sys     0m0.000s

If you're building curl from source or it's an option for you likely just need to enable that option.

Edit: JamesTheAwesomeDude made an excellent point that chasing down where this cURL came from is worth figuring out. In my case it was a fresh EC2 instance running Amazon Linux 2.

$ cat /etc/*-release | grep PRETTY_NAME
PRETTY_NAME="Amazon Linux 2"
2
  • I had the exact same issue, built it from source with the given instructions - it said c-ares was enabled when configuring and libc-ares-dev is installed. But after installing, running curl -V doesn't mention c-ares at all and it doesn't work :/
    – xeruf
    Aug 23, 2020 at 15:40
  • --max-time works perfect on freebsd
    – Igor
    Nov 18 at 19:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .