From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3AC131FF0B4 for ; Fri, 27 Nov 2026 15:04:28 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 61AEA21713; Fri, 27 Nov 2026 15:04:27 +0100 (CET) From: Jakob Klocker To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox-datacenter-manager v2 1/2] connection: allow creating PVE clients with a custom request timeout Date: Fri, 27 Nov 2026 15:03:57 +0100 Message-ID: <20261127140358.205440-2-j.klocker@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261127140358.205440-1-j.klocker@proxmox.com> References: <20261127140358.205440-1-j.klocker@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795788262245 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.066 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: JCYMYY2WQHZF52QT52YFPOK2S4GVD23H X-Message-ID-Hash: JCYMYY2WQHZF52QT52YFPOK2S4GVD23H X-MailFrom: j.klocker@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Some requests to remotes can legitimately take longer than the regular request timeout of 60 seconds, for example exporting the full metric history of a large cluster. Allow creating PVE clients with a different request timeout. Such clients are created separately instead of being taken from the connection cache, so all other requests to the remote keep using the shared cached client with the regular timeout. Signed-off-by: Jakob Klocker --- server/src/connection.rs | 49 +++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/server/src/connection.rs b/server/src/connection.rs index 24aab041..4189fc1b 100644 --- a/server/src/connection.rs +++ b/server/src/connection.rs @@ -261,6 +261,19 @@ pub trait ClientFactory { self.make_pve_client(remote) } + /// Create a new API client for PVE remotes whose requests may take up to `timeout`. + /// + /// The default implementation ignores the `timeout` parameter and forwards to + /// `make_pve_client()`. + fn make_pve_client_with_timeout( + &self, + remote: &Remote, + timeout: Duration, + ) -> Result, Error> { + let _ = timeout; + self.make_pve_client(remote) + } + /// Create a new API client for PVE remotes. /// /// In case the remote has a user configured (instead of an API token), it will connect and get @@ -414,6 +427,17 @@ impl ClientFactory for DefaultClientFactory { } } + fn make_pve_client_with_timeout( + &self, + remote: &Remote, + timeout: Duration, + ) -> Result, Error> { + // Not taken from the connection cache: the cached client is shared with all other + // requests to this remote, which keep the default timeout. + let client = crate::connection::multi_connect(remote)?.with_timeout(timeout); + Ok(Arc::new(PveClientImpl(client))) + } + async fn make_pve_client_and_login(&self, remote: &Remote) -> Result, Error> { let client = connect_or_login(remote, None).await?; Ok(Arc::new(PveClientImpl(client))) @@ -634,11 +658,12 @@ struct MultiClientEntry { /// problems: if we cannot reach a node of a cluster, this will attempt to retry a request on /// another node. /// -/// The 60-second request timeout applies to each endpoint attempt separately. Until failed -/// endpoints enter their back-off, one request can take up to one timeout per endpoint, plus one -/// more when the first endpoint is retried after a connection error. For streamed responses, the -/// timeout limits each wait for body data rather than the whole transfer. Body errors are returned -/// to the consumer without failover or retries. +/// The request timeout applies to each endpoint attempt separately. Until failed endpoints enter +/// their back-off, one request can take up to one timeout per endpoint, plus one more when the +/// first endpoint is retried after a connection error. For streamed responses, the timeout limits +/// each wait for body data rather than the whole transfer. Body errors are returned to the +/// consumer without failover or retries. The timeout defaults to 60 seconds and can be changed +/// with `MultiClient::with_timeout`. /// /// # Possible improvements /// @@ -646,6 +671,7 @@ struct MultiClientEntry { pub struct MultiClient { state: StdMutex, remote: String, + timeout: Duration, } impl MultiClient { @@ -653,9 +679,15 @@ impl MultiClient { Self { state: StdMutex::new(MultiClientState::new(remote.clone(), entries)), remote, + timeout: REQUEST_TIMEOUT, } } + fn with_timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } + fn for_each_client(&self, func: F) where F: Fn(&Arc), @@ -936,7 +968,7 @@ macro_rules! try_request { } let request = client.$how($method.clone(), $path_and_query, params.as_ref()); - match tokio::time::timeout(REQUEST_TIMEOUT, request).await { + match tokio::time::timeout($self.timeout, request).await { // Connection error: the request never reached the server, so failing over to // another node is safe for any method. Remember the first endpoint for retry. Ok(Err(err @ proxmox_client::Error::Connect(_))) => { @@ -1014,7 +1046,7 @@ macro_rules! try_request { let path = $path_and_query; log::warn!("all endpoints failed, retrying {hostname:?} once - {path}"); let request = client.$how($method.clone(), $path_and_query, params.as_ref()); - if let Ok(result) = tokio::time::timeout(REQUEST_TIMEOUT, request).await { + if let Ok(result) = tokio::time::timeout($self.timeout, request).await { if result.is_ok() { if let Ok(mut cache) = crate::remote_cache::RemoteMappingCache::write() { cache.mark_host_reachable( @@ -1082,11 +1114,12 @@ impl HttpApiClient for MultiClient { where T: Serialize + 'a, { + let timeout = self.timeout; let request = try_request! { self, method, path_and_query, params, streaming_request }; Box::pin(async move { request .await - .map(|response| with_body_idle_timeout(response, REQUEST_TIMEOUT)) + .map(|response| with_body_idle_timeout(response, timeout)) }) } } -- 2.47.3