public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH] proxmox-backup-proxy: stop accept() loop on daemon shutdown
@ 2022-04-29  9:20 Dominik Csapak
  2022-04-29  9:43 ` Wolfgang Bumiller
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2022-04-29  9:20 UTC (permalink / raw)
  To: pbs-devel

When a task was running during a reload, the old process would still
accept connections, but drop them due to the closed receiving channel.

This resulted in sporadic connection failures in such a scenario,
depending on which process got the connection.

To fix that poll the shutdown_future too during accept, and exit the
loop then.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 744a93f9..b2badfa6 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -396,12 +396,15 @@ async fn accept_connection(
     let accept_counter = Arc::new(());
 
     loop {
-        let (sock, peer) = match listener.accept().await {
-            Ok(conn) => conn,
-            Err(err) => {
-                eprintln!("error accepting tcp connection: {}", err);
-                continue;
-            }
+        let (sock, peer) = select! {
+            res = listener.accept().fuse() => match res {
+                Ok(conn) => conn,
+                Err(err) => {
+                    eprintln!("error accepting tcp connection: {}", err);
+                    continue;
+                }
+            },
+            _ = proxmox_rest_server::shutdown_future().fuse() => break,
         };
 
         sock.set_nodelay(true).unwrap();
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pbs-devel] [PATCH] proxmox-backup-proxy: stop accept() loop on daemon shutdown
  2022-04-29  9:20 [pbs-devel] [PATCH] proxmox-backup-proxy: stop accept() loop on daemon shutdown Dominik Csapak
@ 2022-04-29  9:43 ` Wolfgang Bumiller
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Bumiller @ 2022-04-29  9:43 UTC (permalink / raw)
  To: Dominik Csapak; +Cc: pbs-devel

one tiny nit inline

On Fri, Apr 29, 2022 at 11:20:17AM +0200, Dominik Csapak wrote:
> When a task was running during a reload, the old process would still
> accept connections, but drop them due to the closed receiving channel.
> 
> This resulted in sporadic connection failures in such a scenario,
> depending on which process got the connection.
> 
> To fix that poll the shutdown_future too during accept, and exit the
> loop then.
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  src/bin/proxmox-backup-proxy.rs | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
> index 744a93f9..b2badfa6 100644
> --- a/src/bin/proxmox-backup-proxy.rs
> +++ b/src/bin/proxmox-backup-proxy.rs
> @@ -396,12 +396,15 @@ async fn accept_connection(
>      let accept_counter = Arc::new(());
>  
>      loop {
> -        let (sock, peer) = match listener.accept().await {
> -            Ok(conn) => conn,
> -            Err(err) => {
> -                eprintln!("error accepting tcp connection: {}", err);
> -                continue;
> -            }
> +        let (sock, peer) = select! {
> +            res = listener.accept().fuse() => match res {
> +                Ok(conn) => conn,
> +                Err(err) => {
> +                    eprintln!("error accepting tcp connection: {}", err);
> +                    continue;
> +                }
> +            },
> +            _ = proxmox_rest_server::shutdown_future().fuse() => break,

I think it would be nicer if we can create the shutdown future once
above the loop rather than calling into the `shutdown_future()` fn each
iteration.

otherwise LGTM




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-29  9:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  9:20 [pbs-devel] [PATCH] proxmox-backup-proxy: stop accept() loop on daemon shutdown Dominik Csapak
2022-04-29  9:43 ` Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal