diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2020-11-30 18:16:48 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-04 21:11:04 +0000 |
commit | 267d28ce067bb213cff816c55bac0b5c1527d500 (patch) | |
tree | b220dbb222a63723832c102a247d7818caca49e2 /src/mongo/util/net/http_client_curl.cpp | |
parent | 2cf65466dd5f37bf1daf4658c02534c06d5a9745 (diff) | |
download | mongo-267d28ce067bb213cff816c55bac0b5c1527d500.tar.gz |
SERVER-51858 Fix curl locking
Diffstat (limited to 'src/mongo/util/net/http_client_curl.cpp')
-rw-r--r-- | src/mongo/util/net/http_client_curl.cpp | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/mongo/util/net/http_client_curl.cpp b/src/mongo/util/net/http_client_curl.cpp index 08f1a8d96fe..c134d0a46b1 100644 --- a/src/mongo/util/net/http_client_curl.cpp +++ b/src/mongo/util/net/http_client_curl.cpp @@ -120,29 +120,64 @@ private: curl_share_setopt(_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); curl_share_setopt(_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); curl_share_setopt(_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION); - curl_share_setopt(_share, CURLSHOPT_USERDATA, &this->_shareMutex); + curl_share_setopt(_share, CURLSHOPT_USERDATA, this); curl_share_setopt(_share, CURLSHOPT_LOCKFUNC, _lockShare); curl_share_setopt(_share, CURLSHOPT_UNLOCKFUNC, _unlockShare); return Status::OK(); } - static void _lockShare(CURL*, curl_lock_data, curl_lock_access, void* ctx) { - reinterpret_cast<stdx::recursive_mutex*>(ctx)->lock(); + static void _lockShare(CURL*, curl_lock_data lock_data, curl_lock_access, void* ctx) { + // curl_lock_access maps to shared and single access, i.e. a read and exclusive lock + // except the unlock method does not have curl_lock_access as a parameter so we map + // all lock requests to regular mutexes + switch (lock_data) { + case CURL_LOCK_DATA_SHARE: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexShare.lock(); + break; + case CURL_LOCK_DATA_DNS: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexDns.lock(); + break; + case CURL_LOCK_DATA_SSL_SESSION: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexSSLSession.lock(); + break; + case CURL_LOCK_DATA_CONNECT: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexConnect.lock(); + break; + default: + fassert(5185801, "Unsupported curl lock type"); + } } - static void _unlockShare(CURL*, curl_lock_data, void* ctx) { - reinterpret_cast<stdx::recursive_mutex*>(ctx)->unlock(); + + static void _unlockShare(CURL*, curl_lock_data lock_data, void* ctx) { + switch (lock_data) { + case CURL_LOCK_DATA_SHARE: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexShare.unlock(); + break; + case CURL_LOCK_DATA_DNS: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexDns.unlock(); + break; + case CURL_LOCK_DATA_SSL_SESSION: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexSSLSession.unlock(); + break; + case CURL_LOCK_DATA_CONNECT: + reinterpret_cast<CurlLibraryManager*>(ctx)->_mutexConnect.unlock(); + break; + default: + fassert(5185802, "Unsupported curl unlock type"); + } } private: bool _initialized = false; CURLSH* _share = nullptr; - // A recursive mutex here is needed because CURL needs to lock this multiple times depending - // on the "internal CURL type" of the object that CURL is sending. Using a normal mutex - // causes the CURL system to deadlock. - stdx::recursive_mutex _shareMutex{}; + Mutex _mutexDns = MONGO_MAKE_LATCH("CurlLibraryManager::ShareDns"); + Mutex _mutexConnect = MONGO_MAKE_LATCH("CurlLibraryManager::ShareConnect"); + Mutex _mutexSSLSession = MONGO_MAKE_LATCH("CurlLibraryManager::ShareSSLSession"); + Mutex _mutexShare = MONGO_MAKE_LATCH("CurlLibraryManager::ShareLock"); + } curlLibraryManager; /** |