Skip to content

Commit

Permalink
Enforce minimum for curl(_file_download)_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Oct 5, 2023
1 parent ac8a9f9 commit 9ec40ce
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions builtin/settingtypes.txt
Expand Up @@ -2099,7 +2099,7 @@ num_emerge_threads (Number of emerge threads) int 1 0 32767
[**cURL]

# Maximum time an interactive request (e.g. server list fetch) may take, stated in milliseconds.
curl_timeout (cURL interactive timeout) int 20000 100 2147483647
curl_timeout (cURL interactive timeout) int 20000 1000 2147483647

# Limits number of parallel HTTP requests. Affects:
# - Media fetch if server uses remote_media setting.
Expand All @@ -2109,7 +2109,7 @@ curl_timeout (cURL interactive timeout) int 20000 100 2147483647
curl_parallel_limit (cURL parallel limit) int 8 1 2147483647

# Maximum time a file download (e.g. a mod download) may take, stated in milliseconds.
curl_file_download_timeout (cURL file download timeout) int 300000 100 2147483647
curl_file_download_timeout (cURL file download timeout) int 300000 5000 2147483647

[**Misc]

Expand Down
4 changes: 2 additions & 2 deletions src/client/clientmedia.cpp
Expand Up @@ -416,8 +416,8 @@ void ClientMediaDownloader::startRemoteMediaTransfers()
fetch_request.url = url;
fetch_request.caller = m_httpfetch_caller;
fetch_request.request_id = m_httpfetch_next_id;
fetch_request.timeout =
g_settings->getS32("curl_file_download_timeout");
fetch_request.timeout = std::max(MIN_HTTPFETCH_TIMEOUT,
(long)g_settings->getS32("curl_file_download_timeout"));
httpfetch_async(fetch_request);

m_remote_file_transfers.insert(std::make_pair(
Expand Down
3 changes: 2 additions & 1 deletion src/gui/guiEngine.cpp
Expand Up @@ -574,7 +574,8 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
HTTPFetchResult fetch_result;
fetch_request.url = url;
fetch_request.caller = HTTPFETCH_SYNC;
fetch_request.timeout = g_settings->getS32("curl_file_download_timeout");
fetch_request.timeout = std::max(MIN_HTTPFETCH_TIMEOUT,
(long)g_settings->getS32("curl_file_download_timeout"));
httpfetch_sync(fetch_request, fetch_result);

if (!fetch_result.succeeded) {
Expand Down
1 change: 1 addition & 0 deletions src/httpfetch.cpp
Expand Up @@ -47,6 +47,7 @@ HTTPFetchRequest::HTTPFetchRequest() :
connect_timeout(10 * 1000),
useragent(std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")")
{
timeout = std::max(timeout, MIN_HTTPFETCH_TIMEOUT_INTERACTIVE);
}


Expand Down
7 changes: 7 additions & 0 deletions src/httpfetch.h
Expand Up @@ -35,6 +35,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Start of regular allocated caller IDs.
#define HTTPFETCH_CID_START 3

namespace {
// lower bound for curl_timeout (see also settingtypes.txt)
constexpr long MIN_HTTPFETCH_TIMEOUT_INTERACTIVE = 1000;
// lower bound for curl_file_download_timeout
constexpr long MIN_HTTPFETCH_TIMEOUT = 5000;
}

// Methods
enum HttpMethod : u8
{
Expand Down

0 comments on commit 9ec40ce

Please sign in to comment.