curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

multi threaded curl segmentation fault

From: Siarhei Siniak via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 18 Jun 2019 10:38:09 +0000 (UTC)

I'm experiencing a rare segmentation fault within libcurl method.
A stack trace is as follows:
#0  0x00007f6f80308b98 in getrn () at lib.so
#1  0x00007f6f80308ffd in lh_delete () at lib.so
#2  0x00007f6f8030a0b1 in int_thread_del_item () at lib.so
#3  0x00007f6f8030b130 in ERR_remove_thread_state () at lib.so
#4  0x00007f6f80288876 in Curl_close () at lib.so
#5  0x00007f6f8026177d in curl_easy_cleanup () at lib.so

The stack trace varies, but is within Curl_close().

I'm doing in the main threaded exclusively the following:
    curl::curl_global_init(CURL_GLOBAL_ALL);Within threads are the following flags and signal related stuff:
    curl::curl_easy_setopt(curl_request.get(), curl::CURLOPT_NOSIGNAL, 1L);

    {
        auto current_sigaction = std::make_unique<struct sigaction>();
        auto default_sigaction = std::make_unique<struct sigaction>();

        // https://curl.haxx.se/mail/lib-2006-01/0170.html
        // https://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly
        // https://stackoverflow.com/questions/32040760/c-openssl-sigpipe-when-writing-in-closed-pipe
        current_sigaction->sa_handler = SIG_IGN;
        sigemptyset(&current_sigaction->sa_mask);

        if (sigaction(SIGPIPE, current_sigaction.get(), default_sigaction.get()) == -1)
        {
            throw std::runtime_error(
                "request_utils_t.request_get, SIGPIPE set ignore handler failure"
            );
        }

        curl_ret_code = curl::curl_easy_perform(curl_request.get());

        if (sigaction(SIGPIPE, default_sigaction.get(), nullptr) == -1)
        {
            throw std::runtime_error(
                "request_utils_t.request_get, SIGPIPE set default handler failure"
            );
        }
    }

Threads are initiated via boost::asio:threaded_pool_executor

I'm using the following statically linked vcpkg of curl:
curl:x64-linux                                     7.61.1-2         A library for transferring data with URLs

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-06-18