Skip to content

Commit 7098332

Browse files
Dispose easy_handle after any curl error (#1445)
It is possible for curl error to be caused by reuse of handle or underlying caches with new network. This occurs on Android after network switch. To be on the safe side, do not reuse handle after any of the curl errors. Relates-To: POSTI-3214 Signed-off-by: Mykhailo Diachenko <ext-mykhailo.z.diachenko@here.com>
1 parent b3425c8 commit 7098332

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,9 @@ ErrorCode NetworkCurl::SendImplementation(
674674
curl_easy_setopt(handle->handle, CURLOPT_CONNECTTIMEOUT_MS,
675675
config.GetConnectionTimeoutDuration().count());
676676
curl_easy_setopt(handle->handle, CURLOPT_SERVER_RESPONSE_TIMEOUT,
677-
std::chrono::duration_cast<std::chrono::seconds>(config.GetTransferTimeoutDuration()).count());
677+
std::chrono::duration_cast<std::chrono::seconds>(
678+
config.GetTransferTimeoutDuration())
679+
.count());
678680
curl_easy_setopt(handle->handle, CURLOPT_WRITEFUNCTION,
679681
&NetworkCurl::RxFunction);
680682
curl_easy_setopt(handle->handle, CURLOPT_WRITEDATA, handle);
@@ -928,8 +930,12 @@ size_t NetworkCurl::HeaderFunction(char* ptr, size_t size, size_t nitems,
928930
void NetworkCurl::CompleteMessage(CURL* handle, CURLcode result) {
929931
std::unique_lock<std::mutex> lock(event_mutex_);
930932

931-
const bool cleanup_easy_handle = (result == CURLE_COULDNT_RESOLVE_PROXY ||
932-
result == CURLE_COULDNT_RESOLVE_HOST);
933+
// When curl returns an error of the handle, it is possible that error
934+
// originates from reuse of easy_handle, eg after network switch on the
935+
// Android.
936+
// To be on the safe side, do not reuse handle and caches attached to the
937+
// handle.
938+
const bool cleanup_easy_handle = result != CURLE_OK;
933939

934940
int index = GetHandleIndex(handle);
935941
if (index >= 0 && index < static_cast<int>(handles_.size())) {

0 commit comments

Comments
 (0)