Skip to content

Commit 5a8801a

Browse files
[release/6.x] Cherry-pick: Curl snags (#7308) (#7310)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 3713c85 commit 5a8801a

File tree

3 files changed

+59
-21
lines changed

3 files changed

+59
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [6.0.14]
9+
10+
[6.0.14]: https://github.com/microsoft/CCF/releases/tag/ccf-6.0.14
11+
12+
### Added
13+
14+
- Improved handling of socket errors in curlm callbacks (#7308)
15+
816
## [6.0.13]
917

1018
[6.0.13]: https://github.com/microsoft/CCF/releases/tag/ccf-6.0.13

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "6.0.13"
7+
version = "6.0.14"
88
authors = [
99
{ name="CCF Team", email="[email protected]" },
1010
]

src/http/curl.h

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ namespace ccf::curl
337337
}
338338
else
339339
{
340-
LOG_INFO_FMT("Ignoring invalid-looking HTTP Header '{}'", header);
340+
LOG_DEBUG_FMT("Ignoring invalid-looking HTTP Header '{}'", header);
341341
}
342342
}
343343
}
@@ -458,7 +458,7 @@ namespace ccf::curl
458458
static void handle_response(
459459
std::unique_ptr<CurlRequest>&& request, CURLcode curl_response_code)
460460
{
461-
LOG_TRACE_FMT("Handling response for {}", request->url);
461+
LOG_DEBUG_FMT("Handling response for {}", request->url);
462462
if (request->response_callback.has_value())
463463
{
464464
long status_code = 0;
@@ -533,7 +533,7 @@ namespace ccf::curl
533533
{
534534
throw std::logic_error("Cannot attach a null CurlRequest");
535535
}
536-
LOG_TRACE_FMT("Attaching CurlRequest to {} to Curlm", request->get_url());
536+
LOG_DEBUG_FMT("Attaching CurlRequest to {} to Curlm", request->get_url());
537537
CURL* curl_handle = request->get_easy_handle();
538538
CHECK_CURL_EASY_SETOPT(curl_handle, CURLOPT_PRIVATE, request.release());
539539
CHECK_CURL_MULTI(curl_multi_add_handle, p.get(), curl_handle);
@@ -642,7 +642,7 @@ namespace ccf::curl
642642
return;
643643
}
644644

645-
LOG_TRACE_FMT("Libuv: processing pending curl requests");
645+
LOG_DEBUG_FMT("Libuv: processing pending curl requests");
646646

647647
std::deque<std::unique_ptr<CurlRequest>> requests_to_add;
648648
{
@@ -672,7 +672,7 @@ namespace ccf::curl
672672
return;
673673
}
674674

675-
LOG_TRACE_FMT("Libuv timeout");
675+
LOG_DEBUG_FMT("Libuv timeout");
676676

677677
int running_handles = 0;
678678
CHECK_CURL_MULTI(
@@ -700,7 +700,7 @@ namespace ccf::curl
700700
return 0;
701701
}
702702

703-
LOG_TRACE_FMT("Curl timeout {}ms", timeout_ms);
703+
LOG_DEBUG_FMT("Curl timeout {}ms", timeout_ms);
704704

705705
if (timeout_ms < 0)
706706
{
@@ -721,12 +721,6 @@ namespace ccf::curl
721721
static void libuv_socket_poll_callback(
722722
uv_poll_t* req, int status, int events)
723723
{
724-
if (status < 0)
725-
{
726-
LOG_FAIL_FMT("Socket poll error: {}", uv_strerror(status));
727-
return;
728-
}
729-
730724
auto* socket_context = static_cast<SocketContextImpl*>(req->data);
731725
if (socket_context == nullptr)
732726
{
@@ -743,11 +737,45 @@ namespace ccf::curl
743737

744738
if (self->is_stopping)
745739
{
746-
LOG_FAIL_FMT("libuv_socket_poll_callback called while stopping");
740+
LOG_FAIL_FMT(
741+
"libuv_socket_poll_callback called on {} while stopped",
742+
socket_context->socket);
743+
return;
744+
}
745+
746+
if (status < 0)
747+
{
748+
if (status == UV_EBADF)
749+
{
750+
// Thrown when POLLERR is thrown by the epoll socket, such as when a
751+
// TCP socket received a reset at a bad time
752+
// https://docs.libuv.org/en/v1.x/poll.html#c.uv_poll_start
753+
// https://github.com/libuv/libuv/issues/3796
754+
LOG_INFO_FMT(
755+
"Socket poll error on {}: {}",
756+
socket_context->socket,
757+
uv_strerror(status));
758+
}
759+
else
760+
{
761+
LOG_FAIL_FMT(
762+
"Socket poll error on {}: {}",
763+
socket_context->socket,
764+
uv_strerror(status));
765+
}
766+
767+
// Notify curl of the error
768+
CHECK_CURL_MULTI(
769+
curl_multi_socket_action,
770+
self->curl_request_curlm,
771+
socket_context->socket,
772+
CURL_CSELECT_ERR,
773+
nullptr);
774+
self->curl_request_curlm.perform();
747775
return;
748776
}
749777

750-
LOG_TRACE_FMT(
778+
LOG_DEBUG_FMT(
751779
"Libuv socket poll callback on {}: {}",
752780
static_cast<int>(socket_context->socket),
753781
static_cast<int>(events));
@@ -786,15 +814,17 @@ namespace ccf::curl
786814
case CURL_POLL_OUT:
787815
case CURL_POLL_INOUT:
788816
{
789-
// Possibly called during shutdown
817+
LOG_DEBUG_FMT(
818+
"Curl socket callback: listen on socket {}, {}",
819+
static_cast<int>(s),
820+
static_cast<int>(action));
821+
822+
// During shutdown ignore requests to add new sockets
790823
if (self->is_stopping)
791824
{
792-
LOG_FAIL_FMT("curl_socket_callback called while stopping");
793825
return 0;
794826
}
795827

796-
LOG_INFO_FMT(
797-
"Curl socket callback: listen on socket {}", static_cast<int>(s));
798828
if (socket_context == nullptr)
799829
{
800830
auto socket_context_ptr = std::make_unique<SocketContextImpl>();
@@ -820,7 +850,7 @@ namespace ccf::curl
820850
case CURL_POLL_REMOVE:
821851
if (socket_context != nullptr)
822852
{
823-
LOG_INFO_FMT(
853+
LOG_DEBUG_FMT(
824854
"CurlmLibuv: curl socket callback: remove socket {}",
825855
static_cast<int>(s));
826856
SocketContext socket_context_ptr(socket_context);
@@ -872,7 +902,7 @@ namespace ccf::curl
872902
LOG_FAIL_FMT("CurlmLibuvContext already closed, cannot attach request");
873903
return;
874904
}
875-
LOG_INFO_FMT("Adding request to {} to queue", request->get_url());
905+
LOG_DEBUG_FMT("Adding request to {} to queue", request->get_url());
876906
std::lock_guard<std::mutex> requests_lock(requests_mutex);
877907
pending_requests.push_back(std::move(request));
878908
uv_async_send(&async_requests_handle);

0 commit comments

Comments
 (0)