cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: download thread hung in poll()

From: Alex Loukissas <alex_at_maginatics.com>
Date: Thu, 3 Nov 2011 10:16:08 -0700

On Thu, Nov 3, 2011 at 2:56 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> So there's also some kind of mutex or semaphore action going on there I
> assume?

So far the readData function has no locking. From what I understand,
this seems to be the root of the problem.

> This is too little information. Does data arrive over the network so that it
> hangs wrongly or is it just that the tranfer stalled? Have you disabled
> signals in your program? What protocol is it hanging on?

Yes, signals are disabled with: curl_easy_setopt(curlHandle,
CURLOPT_NOSIGNAL, 1L);

> It would really help if you code show us the complete source code of an
> application that repeats the problem as otherwise we will mostly just assume
> that the problem is in your code and not in libcurl.

Code snippet:

readData(vector<uri> *uris, curlWriterCb* writeCb, void *userdata) {
    CURL *curlHandle = curl_easy_init();

    curl_easy_setopt(curlHandle, CURLOPT_ERRORBUFFER, errorBuffer);
    curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curlHandle, CURLOPT_FAILONERROR, 1L);
    curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1L);
    curl_easy_setopt(curlHandle, CURLOPT_PUT, 0L);
    curl_easy_setopt(curlHandle, CURLOPT_UPLOAD, 0L);
    curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, NULL);
    if (writeCb) {
        // we have provided a callback that writes directly to file
        DLOG_ASSERT(userdata);
        curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, writeCb);
        curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, userdata);
    } else {
        // no callback provided, use curlWriterCallback that reads
into and returns curlBuffer
        curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriterCallback);
        curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &curlBuffer);
    }

    for ( it = uris->begin() ; it < uris->end(); it++ ) {
        // Now set up remaining curl options
        for (std::map<string, string>::const_iterator headerIt =
                it->httpHeaders.begin();
             headerIt != it->httpHeaders.end();
             ++headerIt) {
            string headerString = headerIt->first;
            headerString.append(": "); // add a header separator
            headerString.append(headerIt->second);
            slist = curl_slist_append(slist, headerString.c_str());
            curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, slist);
        }
        string url = (it)->uri;
        curl_easy_setopt(curlHandle, CURLOPT_URL, url.c_str());

        curl_easy_perform(curlHandle);

        if (slist) {
            curl_slist_free_all(slist);
            slist = NULL;
        }
    }

    if (slist) {
        curl_slist_free_all(slist);
    }

    if (curlHandle) {
        curl_easy_cleanup(curlHandle);
    }
}

>> My question is: would this issue be locking-related?
>
> libcurl itself has no and uses no locks.

So I assume the code above should be guarded with a lock of some sort, correct?
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-11-03