Fix Bug #3463: Force DNS Timeout when forcing a libcurl fresh connection (#3468)

* Force DNS Timeout when forcing a libcurl fresh connection which will force DNS resolution as stale cache internally in curl is not being released
* Fix that 'online' state is correctly set if Internet access is not available at startup when using --monitor
This commit is contained in:
abraunegg 2025-10-10 13:55:31 +11:00 committed by GitHub
commit 35e10ea8e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -575,9 +575,8 @@ int main(string[] cliArgs) {
addLogEntry();
addLogEntry("Unable to reach the Microsoft OneDrive API service at this point in time, re-trying network tests based on applicable intervals");
addLogEntry();
if (!retryInternetConnectivityTest(appConfig)) {
return EXIT_FAILURE;
}
// Run the re-try of Internet connectivity test
online = retryInternetConnectivityTest(appConfig);
}
}

View file

@ -1752,8 +1752,7 @@ class OneDriveApi {
addLogEntry("Internet connectivity to Microsoft OneDrive service has been restored");
}
// unset the fresh connect option as this then creates performance issues if left enabled
if (debugLogging) {addLogEntry("Unsetting libcurl to use a fresh connection as this causes a performance impact if left enabled", ["debug"]);}
curlEngine.http.handle.set(CurlOption.fresh_connect,0);
unsetFreshConnectOption();
}
// On successful processing, break out of the loop
@ -2095,6 +2094,20 @@ class OneDriveApi {
private void setFreshConnectOption() {
if (debugLogging) {addLogEntry("Configuring libcurl to use a fresh connection for re-try", ["debug"]);}
curlEngine.http.handle.set(CurlOption.fresh_connect,1);
// Set libcurl dns_cache_timeout timeout
// https://curl.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html
// https://dlang.org/library/std/net/curl/http.dns_timeout.html
curlEngine.http.dnsTimeout = (dur!"seconds"(0));
}
// Unset the libcurl fresh connection options and reset libcurl DNS Cache Timeout
private void unsetFreshConnectOption() {
if (debugLogging) {addLogEntry("Unsetting libcurl to use a fresh connection as this causes a performance impact if left enabled", ["debug"]);}
curlEngine.http.handle.set(CurlOption.fresh_connect,0);
// Reset libcurl dns_cache_timeout timeout
// https://curl.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html
// https://dlang.org/library/std/net/curl/http.dns_timeout.html
curlEngine.http.dnsTimeout = (dur!"seconds"(appConfig.getValueLong("dns_timeout")));
}
// Generate a HTTP 'reason' based on the HTTP 'code'