From c009c5f43ae0291d0ce0e44b54cd82d50bd3d72b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 29 May 2024 22:50:02 +0200 Subject: Fix default timeouts for z_(fetch|post)_url. When fetching the default timouts from config, the result is converted to an int via `intval()`, the result of that again is compared strictly to `false`. Since 0 !== false, the default values will never be used, and 0 (no timeout) is passed to curl. This cause requests to hang indefinitely (or until they are killed) when receiving actions that require a lookup or fetch to another site as part of the request processing. (E.g webfinger, or fetching objects that we received an announce action for.) This again cause the request never to return a useful status to the site sending the action, and could cause them to think the Hubzilla site is dead. This patch fixes this by comparing the fetched value from config to 0 instead of false, making the defaults work again if the config is not set (or set to 0). --- include/network.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index a7a11ff6e..1978eb868 100644 --- a/include/network.php +++ b/include/network.php @@ -116,7 +116,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { } else { $curl_time = intval(@Config::Get('system','curl_timeout')); - @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); + @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== 0) ? $curl_time : 60)); } if(x($opts,'connecttimeout') && intval($opts['connecttimeout'])) { @@ -124,7 +124,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { } else { $curl_contime = intval(@Config::Get('system','curl_connecttimeout')); - @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (($curl_contime !== false) ? $curl_contime : 30)); + @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (($curl_contime !== 0) ? $curl_contime : 30)); } if(x($opts,'http_auth')) { @@ -298,7 +298,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) { } else { $curl_time = intval(@Config::Get('system','curl_timeout')); - @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); + @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== 0) ? $curl_time : 60)); } if(x($opts,'http_auth')) { -- cgit v1.2.3