all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH backup 1/2] proxy: get rid of some unsafe pins
@ 2021-05-12  7:29 Wolfgang Bumiller
  2021-05-12  7:29 ` [pbs-devel] [PATCH backup 2/2] proxy: fix accept future "rearming" Wolfgang Bumiller
  0 siblings, 1 reply; 2+ messages in thread
From: Wolfgang Bumiller @ 2021-05-12  7:29 UTC (permalink / raw)
  To: pbs-devel

It's easier to follow by just boxing the futures with
Box::pin.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index fc773459..e8c31c4d 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -1,6 +1,5 @@
 use std::sync::Arc;
 use std::path::{Path, PathBuf};
-use std::pin::Pin;
 use std::os::unix::io::AsRawFd;
 
 use anyhow::{bail, format_err, Error};
@@ -220,22 +219,16 @@ async fn accept_connection(
 ) {
     let accept_counter = Arc::new(());
 
-    // Note that these must not be moved out/modified directly, they get pinned in the loop and
-    // "rearmed" after waking up:
-    let mut reload_tls = notify_tls_cert_reload.notified();
-    let mut accept = listener.accept();
+    let mut reload_tls = Box::pin(notify_tls_cert_reload.notified());
+    let mut accept = Box::pin(listener.accept());
 
     loop {
         let sock;
 
-        // normally we'd use `tokio::pin!()` but we need this to happen outside the loop and we
-        // need to be able to "rearm" the futures:
-        let reload_tls_pin = unsafe { Pin::new_unchecked(&mut reload_tls) };
-        let accept_pin = unsafe { Pin::new_unchecked(&mut accept) };
         tokio::select! {
-            _ = reload_tls_pin => {
+            _ = &mut reload_tls => {
                 // rearm the notification:
-                reload_tls = notify_tls_cert_reload.notified();
+                reload_tls = Box::pin(notify_tls_cert_reload.notified());
 
                 log::info!("reloading certificate");
                 match make_tls_acceptor() {
@@ -244,14 +237,14 @@ async fn accept_connection(
                 }
                 continue;
             }
-            res = accept_pin => match res {
+            res = &mut accept => match res {
                 Err(err) => {
                     eprintln!("error accepting tcp connection: {}", err);
                     continue;
                 }
                 Ok((new_sock, _addr)) => {
                     // rearm the accept future:
-                    accept = listener.accept();
+                    accept = Box::pin(listener.accept());
 
                     sock = new_sock;
                 }
-- 
2.20.1





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

* [pbs-devel] [PATCH backup 2/2] proxy: fix accept future "rearming"
  2021-05-12  7:29 [pbs-devel] [PATCH backup 1/2] proxy: get rid of some unsafe pins Wolfgang Bumiller
@ 2021-05-12  7:29 ` Wolfgang Bumiller
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Bumiller @ 2021-05-12  7:29 UTC (permalink / raw)
  To: pbs-devel

this must happen regardless of whether we got an error

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index e8c31c4d..4bf3fb56 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -237,16 +237,18 @@ async fn accept_connection(
                 }
                 continue;
             }
-            res = &mut accept => match res {
-                Err(err) => {
-                    eprintln!("error accepting tcp connection: {}", err);
-                    continue;
-                }
-                Ok((new_sock, _addr)) => {
-                    // rearm the accept future:
-                    accept = Box::pin(listener.accept());
-
-                    sock = new_sock;
+            res = &mut accept => {
+                // rearm the accept future:
+                accept = Box::pin(listener.accept());
+
+                match res {
+                    Err(err) => {
+                        eprintln!("error accepting tcp connection: {}", err);
+                        continue;
+                    }
+                    Ok((new_sock, _addr)) => {
+                        sock = new_sock;
+                    }
                 }
             }
         };
-- 
2.20.1





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

end of thread, other threads:[~2021-05-12  7:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  7:29 [pbs-devel] [PATCH backup 1/2] proxy: get rid of some unsafe pins Wolfgang Bumiller
2021-05-12  7:29 ` [pbs-devel] [PATCH backup 2/2] proxy: fix accept future "rearming" Wolfgang Bumiller

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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal