Skip to content

Commit ac8ddd7

Browse files
committed
Merge branch 'ew/http-do-not-forget-to-call-curl-multi-remove-handle'
The http transport (with curl-multi option, which is the default these days) failed to remove curl-easy handle from a curlm session, which led to unnecessary API failures. * ew/http-do-not-forget-to-call-curl-multi-remove-handle: http: always remove curl easy from curlm session on release http: consolidate #ifdefs for curl_multi_remove_handle http: warn on curl_multi_add_handle failures
2 parents 570b449 + 2abc848 commit ac8ddd7

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

http.c

+18-11
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ static void finish_active_slot(struct active_request_slot *slot)
201201
slot->callback_func(slot->callback_data);
202202
}
203203

204+
static void xmulti_remove_handle(struct active_request_slot *slot)
205+
{
206+
#ifdef USE_CURL_MULTI
207+
curl_multi_remove_handle(curlm, slot->curl);
208+
#endif
209+
}
210+
204211
#ifdef USE_CURL_MULTI
205212
static void process_curl_messages(void)
206213
{
@@ -216,7 +223,7 @@ static void process_curl_messages(void)
216223
slot->curl != curl_message->easy_handle)
217224
slot = slot->next;
218225
if (slot != NULL) {
219-
curl_multi_remove_handle(curlm, slot->curl);
226+
xmulti_remove_handle(slot);
220227
slot->curl_result = curl_result;
221228
finish_active_slot(slot);
222229
} else {
@@ -881,9 +888,7 @@ void http_cleanup(void)
881888
while (slot != NULL) {
882889
struct active_request_slot *next = slot->next;
883890
if (slot->curl != NULL) {
884-
#ifdef USE_CURL_MULTI
885-
curl_multi_remove_handle(curlm, slot->curl);
886-
#endif
891+
xmulti_remove_handle(slot);
887892
curl_easy_cleanup(slot->curl);
888893
}
889894
free(slot);
@@ -1022,6 +1027,8 @@ int start_active_slot(struct active_request_slot *slot)
10221027

10231028
if (curlm_result != CURLM_OK &&
10241029
curlm_result != CURLM_CALL_MULTI_PERFORM) {
1030+
warning("curl_multi_add_handle failed: %s",
1031+
curl_multi_strerror(curlm_result));
10251032
active_requests--;
10261033
slot->in_use = 0;
10271034
return 0;
@@ -1161,13 +1168,13 @@ void run_active_slot(struct active_request_slot *slot)
11611168
static void release_active_slot(struct active_request_slot *slot)
11621169
{
11631170
closedown_active_slot(slot);
1164-
if (slot->curl && curl_session_count > min_curl_sessions) {
1165-
#ifdef USE_CURL_MULTI
1166-
curl_multi_remove_handle(curlm, slot->curl);
1167-
#endif
1168-
curl_easy_cleanup(slot->curl);
1169-
slot->curl = NULL;
1170-
curl_session_count--;
1171+
if (slot->curl) {
1172+
xmulti_remove_handle(slot);
1173+
if (curl_session_count > min_curl_sessions) {
1174+
curl_easy_cleanup(slot->curl);
1175+
slot->curl = NULL;
1176+
curl_session_count--;
1177+
}
11711178
}
11721179
#ifdef USE_CURL_MULTI
11731180
fill_active_slots();

0 commit comments

Comments
 (0)