@@ -678,21 +678,28 @@ ErrorCode NetworkCurl::SendImplementation(
678
678
679
679
const auto & config = request.GetSettings ();
680
680
681
- RequestHandle* handle = InitRequestHandle ();
681
+ RequestHandle* handle = [&] {
682
+ std::lock_guard<std::mutex> lock (event_mutex_);
683
+
684
+ auto * request_handle = InitRequestHandleUnsafe ();
685
+
686
+ if (request_handle) {
687
+ request_handle->id = id;
688
+ request_handle->out_completion_callback = std::move (callback);
689
+ request_handle->out_header_callback = std::move (header_callback);
690
+ request_handle->out_data_callback = std::move (data_callback);
691
+ request_handle->out_data_stream = payload;
692
+ request_handle->request_body = request.GetBody ();
693
+ request_handle->request_headers = SetupHeaders (request.GetHeaders ());
694
+ }
695
+
696
+ return request_handle;
697
+ }();
698
+
682
699
if (!handle) {
683
700
return ErrorCode::NETWORK_OVERLOAD_ERROR;
684
701
}
685
702
686
- handle->id = id;
687
-
688
- // Set request output callbacks
689
- handle->out_completion_callback = std::move (callback);
690
- handle->out_header_callback = std::move (header_callback);
691
- handle->out_data_callback = std::move (data_callback);
692
- handle->out_data_stream = payload;
693
- handle->request_body = request.GetBody ();
694
- handle->request_headers = SetupHeaders (request.GetHeaders ());
695
-
696
703
OLP_SDK_LOG_DEBUG (kLogTag ,
697
704
" Send request with url="
698
705
<< utils::CensorCredentialsInUrl (request.GetUrl ())
@@ -868,9 +875,7 @@ void NetworkCurl::AddEvent(EventInfo::Type type, RequestHandle* handle) {
868
875
#endif
869
876
}
870
877
871
- NetworkCurl::RequestHandle* NetworkCurl::InitRequestHandle () {
872
- std::lock_guard<std::mutex> lock (event_mutex_);
873
-
878
+ NetworkCurl::RequestHandle* NetworkCurl::InitRequestHandleUnsafe () {
874
879
const auto unused_handle_it =
875
880
std::find_if (handles_.begin (), handles_.end (),
876
881
[](const RequestHandle& request_handle) {
@@ -1162,7 +1167,8 @@ void NetworkCurl::Run() {
1162
1167
msgs.push_back (curl_handle);
1163
1168
}
1164
1169
}
1165
- } else {
1170
+ } else if (event.type == EventInfo::Type::CANCEL_EVENT &&
1171
+ request_handle->is_cancelled ) {
1166
1172
// The Request was canceled, remove it from curl
1167
1173
auto code = curl_multi_remove_handle (curl_, curl_handle);
1168
1174
if (code != CURLM_OK) {
0 commit comments