From 35e10ea8e6b6759c21df044eae0092b42f7c09c0 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 10 Oct 2025 13:55:31 +1100 Subject: [PATCH] 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 --- src/main.d | 5 ++--- src/onedrive.d | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.d b/src/main.d index ad041957..3e1876f2 100644 --- a/src/main.d +++ b/src/main.d @@ -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); } } diff --git a/src/onedrive.d b/src/onedrive.d index 65919ce8..08ef7caa 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -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'