attempt to prevent crash on curl error 6
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
7292fc11cf
commit
5a823f975c
@ -43,15 +43,12 @@
|
|||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
[[nodiscard]] auto set_request_path(auto &request,
|
[[nodiscard]] auto set_request_path(auto &request, std::string_view object_name)
|
||||||
const std::string &object_name)
|
|
||||||
-> repertory::api_error {
|
-> repertory::api_error {
|
||||||
request.path = object_name;
|
request.path = object_name;
|
||||||
if (request.path.substr(1U).size() > repertory::max_s3_object_name_length) {
|
return (request.path.substr(1U).size() > repertory::max_s3_object_name_length)
|
||||||
return repertory::api_error::name_too_long;
|
? repertory::api_error::name_too_long
|
||||||
}
|
: repertory::api_error::success;
|
||||||
|
|
||||||
return repertory::api_error::success;
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -833,11 +830,15 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
|
|||||||
&stop_requested](std::size_t read_size, std::size_t read_offset,
|
&stop_requested](std::size_t read_size, std::size_t read_offset,
|
||||||
data_buffer &read_buffer) -> api_error {
|
data_buffer &read_buffer) -> api_error {
|
||||||
auto res{api_error::error};
|
auto res{api_error::error};
|
||||||
for (std::uint32_t idx = 0U;
|
for (std::uint32_t idx{0U};
|
||||||
not(stop_requested || app_config::get_stop_requested()) &&
|
not(stop_requested || app_config::get_stop_requested()) &&
|
||||||
res != api_error::success &&
|
res != api_error::success &&
|
||||||
idx < get_config().get_retry_read_count() + 1U;
|
idx < get_config().get_retry_read_count() + 1U;
|
||||||
++idx) {
|
++idx) {
|
||||||
|
if (idx > 0U) {
|
||||||
|
std::this_thread::sleep_for(1s);
|
||||||
|
}
|
||||||
|
|
||||||
curl::requests::http_get get{};
|
curl::requests::http_get get{};
|
||||||
get.aws_service = "aws:amz:" + cfg.region + ":s3";
|
get.aws_service = "aws:amz:" + cfg.region + ":s3";
|
||||||
get.headers["response-content-type"] = "binary/octet-stream";
|
get.headers["response-content-type"] = "binary/octet-stream";
|
||||||
@ -849,37 +850,35 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
|
|||||||
long /*response_code*/) {
|
long /*response_code*/) {
|
||||||
read_buffer = response_data;
|
read_buffer = response_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
res = set_request_path(get, object_name);
|
res = set_request_path(get, object_name);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
long response_code{};
|
const auto notify_retry = [=](long response_code) {
|
||||||
const auto notify_retry = [&]() {
|
auto msg =
|
||||||
|
fmt::format("read file bytes failed|offset|{}|size|{}|retry|{}",
|
||||||
|
std::to_string(read_offset),
|
||||||
|
std::to_string(read_size), std::to_string(idx + 1U));
|
||||||
if (response_code == 0) {
|
if (response_code == 0) {
|
||||||
utils::error::raise_api_path_error(
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
function_name, api_path, api_error::comm_error,
|
api_error::comm_error, msg);
|
||||||
"read file bytes failed|offset|" + std::to_string(read_offset) +
|
|
||||||
"|size|" + std::to_string(read_size) + "|retry|" +
|
|
||||||
std::to_string(idx + 1U));
|
|
||||||
} else {
|
} else {
|
||||||
utils::error::raise_api_path_error(
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
function_name, api_path, response_code,
|
response_code, msg);
|
||||||
"read file bytes failed|offset|" + std::to_string(read_offset) +
|
|
||||||
"|size|" + std::to_string(read_size) + "|retry|" +
|
|
||||||
std::to_string(idx + 1U));
|
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(1s);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
long response_code{};
|
||||||
if (not get_comm().make_request(get, response_code, stop_requested)) {
|
if (not get_comm().make_request(get, response_code, stop_requested)) {
|
||||||
notify_retry();
|
notify_retry(response_code);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response_code < http_error_codes::ok ||
|
if (response_code < http_error_codes::ok ||
|
||||||
response_code >= http_error_codes::multiple_choices) {
|
response_code >= http_error_codes::multiple_choices) {
|
||||||
notify_retry();
|
notify_retry(response_code);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user