cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: curl loop hangs

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 21 Oct 2011 13:06:54 -0700

On Fri, Oct 21, 2011 at 05:23:34PM +0200, Ronald Müller wrote:
> Here is a (very) simplified version of my script. On most of my systems this
> script runs without any problems and without hang. But on the one system this
> test script hangs after a while, even if the requested host/port isn't
> available/open.
>
> Do you have a hint what could cause the hang on the problematic system?

Are you using any timeout options?

> Output of the script
> ..
> ..
> Cycle: 15973
> curl: (7) couldn't connect to host
> Cycle: 15974
> curl: (7) couldn't connect to host
> Cycle: 15975
> curl: (7) couldn't connect to host
> Cycle: 15976
> curl: (7) couldn't connect to host
>
> GET /port/does/not/exist/ HTTP/1.1
> User-Agent: curl/7.22.0 (i686-redhat-linux-gnu) libcurl/7.22.0
> OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: localhost:11111
> Accept: */*
>
> --> Here the script just hangs and doesn't return.

curl won't send the GET request until it connects to the remote server. So,
in this case it DID connect (to the allegedly unavailable port) and sent the
request. At that point it will wait for the response, and since HTTP doesn't
specify any timeouts, it will wait forever. If whatever it was that answered
on port 11111 acts like port 9 (the discard port), then curl will never exit,
by design.

You will want to add a timeout or speed limit option to have curl detect this
condition and eventually abort.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-10-21