cURL / Mailing Lists / curl-library / Single Mail


SessionHandle is waiting for resolve, but CURL_POLL_REMOVE is called to sockect callback and leads to Connection Closing

From: supercaowei <>
Date: Fri, 3 Jun 2016 17:04:51 +0800

Dear Masters:
Recently I have had a trouble with the cURL library.
I sent an https request and the server answered me with a redirected url. So the redirected url request would be automatically sent.
But, before it was sent ( function "Curl_http" was not executed, and the session handle's mstate was CURLM_STATE_WAITRESOLVE ) , the execution entered the function "singlesocket" in file multi.c. Then, CURL_POLL_REMOVE was called to the sockect callabck set by me. So, the socket was removed. In result, the whole session handle was removed too and the corresponding connection is closed. That means, the redirected url request was never sent.

I traced into the function "singlesocket" in file multi.c, it was executed like below :
static void singlesocket(struct Curl_multi *multi, struct SessionHandle *data)
curl_socket_t socks[MAX_SOCKSPEREASYHANDLE];
       int i;
       struct Curl_sh_entry *entry;
       curl_socket_t s;
       int num;
       unsigned int curraction;
       bool remove_sock_from_hash;

// data->mstate == CURLM_STATE_WAITRESOLVE
curraction = multi_getsock(data, socks, MAX_SOCKSPEREASYHANDLE); // curraction = 0
for(i=0; (i< MAX_SOCKSPEREASYHANDLE) && (curraction & (GETSOCK_READSOCK(i) | GETSOCK_WRITESOCK(i))); i++)
// did not enter this loop

num = i; // num = 0
for(i=0; i< data->numsocks; i++) // data->numsocks == 1
       int j;
              s = data->sockets[i];
              for(j=0; j<num; j++)
// did not enter this loop
              if(s != CURL_SOCKET_BAD)
                  remove_sock_from_hash = TRUE;
    entry = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); // the sockect list already has this entry
                  ... // in the following codes, remove_sock_from_hash did not change to FALSE.
                    sh_delentry(multi->sockhash, s);

Later, in the socket_cb, I checked how many active sockets the session handle still has. When I find it's 0, I destroyed the session handle. As a result, the corresponding connection is closed. That means, the redirected url request was never sent.
Can you tell me how to fix this problem and get the request sent ?



List admin:
Received on 2016-06-03