From: Jakob Klocker <j.klocker@proxmox.com>
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 [thread overview]
Message-ID: <20261127140358.205440-2-j.klocker@proxmox.com> (raw)
In-Reply-To: <20261127140358.205440-1-j.klocker@proxmox.com>
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 <j.klocker@proxmox.com>
---
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<Arc<PveClient>, 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<Arc<PveClient>, 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<Arc<PveClient>, 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<MultiClientState>,
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<F>(&self, func: F)
where
F: Fn(&Arc<Client>),
@@ -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
next prev parent reply other threads:[~2026-11-27 14:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 14:03 [PATCH proxmox-datacenter-manager v2 0/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker
2026-11-27 14:03 ` Jakob Klocker [this message]
2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 2/2] " Jakob Klocker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127140358.205440-2-j.klocker@proxmox.com \
--to=j.klocker@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.