[pdm-devel] [PATCH] api server: make incoming connection handling robust
Fabian Grünbichler
f.gruenbichler at proxmox.com
Fri Aug 8 10:26:26 CEST 2025
breaking from this loop when encountering an error means no longer accepting
new connections, and must be avoided at all costs.
this matches the changes in proxmox-backup-server for the same issue.
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
server/src/bin/proxmox-datacenter-api/main.rs | 16 ++++++++++------
.../bin/proxmox-datacenter-privileged-api.rs | 18 ++++++++++++++----
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/server/src/bin/proxmox-datacenter-api/main.rs b/server/src/bin/proxmox-datacenter-api/main.rs
index e92232e..db6b258 100644
--- a/server/src/bin/proxmox-datacenter-api/main.rs
+++ b/server/src/bin/proxmox-datacenter-api/main.rs
@@ -278,13 +278,17 @@ async fn run(debug: bool) -> Result<(), Error> {
Some(conn) = secure_connections.next() => {
match conn {
Ok(conn) => {
- let api_service = rest_server.api_service(&conn)?;
- let watcher = graceful.watcher();
- tokio::spawn(async move {
- api_service.serve(conn, Some(watcher)).await
- });
+ match rest_server.api_service(&conn) {
+ Ok(api_service) => {
+ let watcher = graceful.watcher();
+ tokio::spawn(async move {
+ api_service.serve(conn, Some(watcher)).await
+ });
+ }
+ Err(err) => log::warn!("Failed to get api service: {err:?}"),
+ }
},
- Err(err) => { log::warn!("Failed to accept insecure connection: {err:?}"); }
+ Err(err) => { log::warn!("Failed to accept secure connection: {err:?}"); }
}
},
_shutdown = proxmox_daemon::shutdown_future() => {
diff --git a/server/src/bin/proxmox-datacenter-privileged-api.rs b/server/src/bin/proxmox-datacenter-privileged-api.rs
index b62f4ea..66033eb 100644
--- a/server/src/bin/proxmox-datacenter-privileged-api.rs
+++ b/server/src/bin/proxmox-datacenter-privileged-api.rs
@@ -181,10 +181,20 @@ async fn run() -> Result<(), Error> {
loop {
tokio::select! {
incoming = listener.accept() => {
- let (conn, _) = incoming?;
- let api_service = rest_server.api_service(&conn)?;
- let watcher = graceful.watcher();
- tokio::spawn(async move { api_service.serve(conn, Some(watcher)).await });
+ match incoming {
+ Ok((conn, _)) => {
+ match rest_server.api_service(&conn) {
+ Ok(api_service) => {
+ let watcher = graceful.watcher();
+ tokio::spawn(async move {
+ api_service.serve(conn, Some(watcher)).await
+ });
+ }
+ Err(err) => log::warn!("Failed to get api service: {err:?}"),
+ }
+ },
+ Err(err) => log::warn!("Failed to accept secure connection: {err:?}"),
+ };
},
_shutdown = proxmox_daemon::shutdown_future() => {
break;
--
2.47.2
More information about the pdm-devel
mailing list