infinite loop in libcurl
Date: Tue, 25 Mar 2014 15:51:41 +0000
I am using version 7.34.0 of libcurl on Linux.
Recently we were running a stress test against our software doing a lot of http requests against a server that we are developing. Things worked fine for a while, but eventually our program quit getting any response from the server and our client was using up all of the cpu time on a 24 cpu box. I ran pstack against our client to see what it was doing and found that all of our threads which get data from the server were in the libcurl function Curl_connecthost. Since this was a reproducible problem I replaced the version of libcurl I had originally with a version that printed out some debug information. What I found was that it was looping endlessly on the following while loop in Curl_connecthost with res equal to 7 (CURLE_COULDNT_CONNECT) and the system error was 99 (EADDRNOTAVAIL).
/* start connecting to first IP */
res = singleipconnect(conn, conn->tempaddr, &(conn->tempsock));
while(res != CURLE_OK &&
conn->tempsock == CURL_SOCKET_BAD)
res = trynextip(conn, FIRSTSOCKET, 0);
While our client is multi-threaded, currently I am not doing any sharing of curl handles even among requests issued on the same thread.
I verified that neither the client nor the server had run out of file handles and in fact each was only using a handful of sockets.
The server we are talking to is under development so may well be buggy, but I would not expect even a buggy server to be able to put libcurl into an infinite loop. Can someone explain the details of what that while loop is doing and why it might get into an infinite loop?
Here is a full stack trace of the libcurl code when it is in the infinitie loop:
#0 trynextip (conn=0x7f42280147d0, sockindex=0, tempindex=0) at curl/lib/connect.c:582
#1 0x00007f43d2757779 in Curl_connecthost (conn=0x7f42280147d0, remotehost=0x7f4228015510) at curl/lib/connect.c:1112
#2 0x00007f43d279fa01 in Curl_setup_conn (conn=0x7f42280147d0, protocol_done=0x7f43927f1ded) at curl/lib/url.c:5573
#3 0x00007f43d279fb2b in Curl_connect (data=0x7f4228002860, in_connect=0x7f4228002870, asyncp=0x7f43927f1dee, protocol_done=0x7f43927f1ded)
#4 0x00007f43d277c474 in multi_runsingle (multi=0x7f422800b670, now=..., data=0x7f4228002860) at curl/lib/multi.c:1024
#5 0x00007f43d277d972 in curl_multi_perform (multi_handle=0x7f422800b670, running_handles=0x7f43927f1eec) at curl/lib/multi.c:1727
#6 0x00007f43d275aefc in easy_transfer (multi=0x7f422800b670) at curl/lib/easy.c:705
#7 0x00007f43d275b07c in easy_perform (data=0x7f4228002860, events=false) at curl/lib/easy.c:784
#8 0x00007f43d275b0b4 in curl_easy_perform (easy=0x7f4228002860) at curl/lib/easy.c:803
List admin: http://cool.haxx.se/list/listinfo/curl-library
Received on 2014-03-25