Skip to content

Commit

Permalink
fix: workaround curl_multi_poll returning an error on EINTR (#11649)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou authored May 19, 2023
1 parent 65f30c0 commit dbe9fbe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions google/cloud/internal/curl_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,27 @@ Status CurlImpl::PerformWorkUntil(absl::FunctionRef<bool()> predicate) {
Status CurlImpl::WaitForHandles(int& repeats) {
int const timeout_ms = 1000;
int numfds = 0;
CURLMcode result;
#if CURL_AT_LEAST_VERSION(7, 66, 0)
CURLMcode result =
curl_multi_poll(multi_.get(), nullptr, 0, timeout_ms, &numfds);
// Use curl_multi_poll()
#if CURL_AT_LEAST_VERSION(7, 84, 0)
// Work around https://github.com/curl/curl/issues/11135 by retrying
// when EINTR fails poll(). We want to retry so that post-poll()
// curl_multi bookkeeping code runs.
do {
errno = 0;
result = curl_multi_poll(multi_.get(), nullptr, 0, timeout_ms, &numfds);
} while (result == CURLM_UNRECOVERABLE_POLL && errno == EINTR);
#else
// EINTR will be simply ignored by curl_multi_poll().
result = curl_multi_poll(multi_.get(), nullptr, 0, timeout_ms, &numfds);
#endif
TRACE_STATE() << ", numfds=" << numfds << ", result=" << result
<< ", repeats=" << repeats;
if (result != CURLM_OK) return AsStatus(result, __func__);
#else
CURLMcode result =
curl_multi_wait(multi_.get(), nullptr, 0, timeout_ms, &numfds);
// Use curl_multi_wait()
result = curl_multi_wait(multi_.get(), nullptr, 0, timeout_ms, &numfds);
TRACE_STATE() << ", numfds=" << numfds << ", result=" << result
<< ", repeats=" << repeats;
if (result != CURLM_OK) return AsStatus(result, __func__);
Expand Down

0 comments on commit dbe9fbe

Please sign in to comment.