From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 579AB7B3EA for ; Wed, 12 May 2021 09:30:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4972A9998 for ; Wed, 12 May 2021 09:29:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 212DD9983 for ; Wed, 12 May 2021 09:29:42 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DCCF246556 for ; Wed, 12 May 2021 09:29:36 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Wed, 12 May 2021 09:29:30 +0200 Message-Id: <20210512072931.2882-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.018 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH backup 1/2] proxy: get rid of some unsafe pins X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2021 07:30:13 -0000 It's easier to follow by just boxing the futures with Box::pin. Signed-off-by: Wolfgang Bumiller --- 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