Skip to content

CurlEasyClient is not thread-safe #124

@morten-ofstad

Description

@morten-ofstad

The CurlEasyClient class calls curl_global_init/curl_global_cleanup in its constructor/destructor. These functions increase/decrease an initialized count, but when called from multiple threads this breaks since it's not using an atomic increment/decrement (the initialized count gets read and increased by two threads and then written with the new value which is only increased by one, or similar in the destructor). This lead to crashes when running one of our application for several hours because curl would suddenly be deinitialized when it shouldn't be.

We've had to patch azure-storage-cpplite to remove the calls to curl_global_init/curl_global_cleanup from the CurlEasyClient class, but this change could possibly break other applications that depend on automatic cleanup when using azure-storage-cpplite in a single-threaded application so I'm not sure how you would want to solve this. curl_easy_init will automatically call curl_global_init if it hasn't already been called, but in that case it won't clean up on exit (see https://github.com/curl/curl/blob/master/lib/easy.c).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions