Skip to content

Commit b11248d

Browse files
author
Paweł Andruszkiewicz
committed
BUG#35392531 Recreate CURL connection on retry
In order to avoid issues caused by unexpected CURL states, the CURL connection is recreated whenever an HTTP(S) request needs to be retried. Additionally, requests are automatically retried on the following error: CURLE_OPERATION_TIMEDOUT (28). Change-Id: I79bf0498a4930ca50b1a96fa32aa506d8f0ace3c (cherry picked from commit 002c54e50dafb5e3cfc0eacb7333eab3ec8dc60f)
1 parent befb0ca commit b11248d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

mysqlshdk/libs/rest/rest_service.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ class Rest_service::Impl {
385385

386386
const Masked_string &base_url() const { return m_base_url; }
387387

388+
void reset_connection() {
389+
m_handle.reset(curl_easy_duphandle(m_handle.get()));
390+
}
391+
388392
private:
389393
void verify_ssl(bool verify) {
390394
curl_easy_setopt(m_handle.get(), CURLOPT_SSL_VERIFYHOST, verify ? 2L : 0L);
@@ -588,6 +592,7 @@ Response::Status_code Rest_service::execute(Request *request,
588592
}
589593

590594
const auto retry = [&response, &retry_strategy, this](const char *msg) {
595+
m_impl->reset_connection();
591596
if (response && response->body) response->body->clear();
592597
retry_strategy->wait_for_retry();
593598
// this log is to have visibility of the error

mysqlshdk/libs/rest/retry_strategy.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ std::unique_ptr<Retry_strategy> default_retry_strategy() {
5757
// retry in case of partial file error reported by CURL, can happen due to a
5858
// network error, when received data is shorter than reported
5959
retry_strategy->add_retriable_error_code(Error_code::PARTIAL_FILE);
60+
// retry if operation times out, sometimes servers get stuck...
61+
retry_strategy->add_retriable_error_code(Error_code::OPERATION_TIMEDOUT);
6062

6163
// Throttling handling: equal jitter guarantees some wait time before next
6264
// attempt

0 commit comments

Comments
 (0)