Fry Simpson
Fry Simpson

Reputation: 1275

curl ignoring --connect-timeout parameter

I am running the following curl command from a Windows batch (in a Jenkins job, for what it's worth):

C:\>curl --connect-timeout 240 --user <myuser> --header "Content-Type: text/xml;charset=UTF-8" --data @C:\dataOut\myData.xml http://www.myURL.it/myApi.asmx -o C:\dataIn\mtResponse.xml --verbose

When the server is fast enough everything goes right, but occasionally the reply is slow and the connection times out.

I thought that the --connect-timeout 240 parameter would have set the conection timeout to 240 seconds (i.e. 4 minutes), nonetheless the connection seems to timeout after 20 seconds:

  0     0    0     0    0     0      0      0 --:--:--  0:00:20 --:--:--     0* connect to N.N.N.N port 80 failed: Timed out

The complete output is the following:

C:\>curl --connect-timeout 240 --user <myuser> --header "Content-Type: text/xml;charset=UTF-8" --data @C:\dataOut\myData.xml http://www.myURL.it/myApi.asmx -o C:\dataIn\mtResponse.xml --verbose 
29/06/2020 16:33:06   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
29/06/2020 16:33:06                                  Dload  Upload   Total   Spent    Left  Speed
29/06/2020 16:33:06 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying N.N.N.N...
29/06/2020 16:33:07 * TCP_NODELAY set
29/06/2020 16:33:07 
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:06 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:07 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:08 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:09 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:10 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:11 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:13 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:14 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:15 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:16 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:17 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:18 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:19 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:20 --:--:--     0* connect to N.N.N.N port 80 failed: Timed out
29/06/2020 16:33:27 * Failed to connect to www.myURL.it port 80: Timed out
29/06/2020 16:33:27 
  0     0    0     0    0     0      0      0 --:--:--  0:00:21 --:--:--     0
29/06/2020 16:33:27 * Closing connection 0
29/06/2020 16:33:27 curl: (7) Failed to connect to www.myURL.it port 80: Timed out
29/06/2020 16:33:27 

And my curl version is the following:

C:\>curl --version
curl 7.64.1 (x86_64-pc-win32) libcurl/7.64.1 OpenSSL/1.1.1b (Schannel) zlib/1.2.11 brotli/1.0.7 WinIDN libssh2/1.8.2 nghttp2/1.37.0
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP brotli libz

What am I missing to keep curl waiting for server for at least 240 seconds?

Upvotes: 0

Views: 3874

Answers (1)

Samson Scharfrichter
Samson Scharfrichter

Reputation: 9067

Did you try reading the curl documentation? It is full of interesting things.

For instance, big surprise, the "connect timeout" is about CONNECTING to the server i.e. checking that it is alive. It does not care about the time it takes for the server to give its full RESPONSE.

Since the full documentation is quite long, just zoom on a tutorial about timeouts:
https://ec.haxx.se/usingcurl/usingcurl-timeouts

Never spend more than this to connect
curl --connect-timeout 2.37

Maximum time allowed to spend
curl --max-time 5.5

Transfer speeds slower than this means exit (alternative to a fixed time-out)
curl --speed-time 15 --speed-limit 1000

Upvotes: 2

Related Questions