Skip to content

Commit

Permalink
[command][service] Set short timeout explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Mar 5, 2024
1 parent 317cff7 commit cfd4300
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/sw/client/common/cl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@ command_line:
run:
type: bool
desc: run upgrade commands immediately
short_timeouts:
type: bool
desc: do not wait for http responses for a default amount of time
git_sources:
type: path
desc: "Specify git sources file to read from. Each file specifies as follow: \"source url\" \"tag\"."
Expand Down
21 changes: 17 additions & 4 deletions src/sw/client/common/command/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DECLARE_STATIC_LOGGER(logger, "service");

namespace {
bool has_prefix;
bool short_timeouts;
}

struct http_request_cache {
Expand All @@ -38,7 +39,10 @@ struct http_request_cache {
data &test_url1(auto &&key_url, std::string additional_url, HttpRequest &request, bool exception = false) {
auto &source_id = key_url; // d.source has real tag so it is now useful
if (new_versions[source_id].http_code == 0) {
request.connect_timeout = 1;
if (short_timeouts)
{
request.connect_timeout = 1;
}
request.url = key_url + additional_url;
try
{
Expand All @@ -50,7 +54,10 @@ struct http_request_cache {
{
std::string err = e.what();
boost::to_lower(err);
new_versions[source_id].http_code = err.contains("timeout") ? 1 : 2;
if (short_timeouts)
{
new_versions[source_id].http_code = err.contains("timeout") ? 1 : 2;
}
if (exception) {
throw;
}
Expand Down Expand Up @@ -301,7 +308,10 @@ void update_packages(SwClientContext &swctx) {
LOG_INFO(logger, "remote: " << remote->url);
auto &source_id = remote->url; // d.source has real tag so it is now useful
HttpRequest request{httpSettings};
request.timeout = 1;
if (short_timeouts)
{
request.timeout = 1;
}
if (auto &ret = cache.test_url1(source_id, {}, request); ret.http_code != 200)
{
LOG_WARN(logger, "http " << ret.http_code << ": " << resolved.begin()->second.toString());
Expand Down Expand Up @@ -592,7 +602,10 @@ struct package_updater {
continue;
}
HttpRequest request{httpSettings};
request.timeout = 1;
if (short_timeouts)
{
request.timeout = 1;
}
try {
auto &cache_record = cache.test_url1(rf2.url, {}, request);
if (cache_record.http_code != 200 && cache_record.http_code != 1) {
Expand Down

0 comments on commit cfd4300

Please sign in to comment.