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 D90DC65E2B for ; Thu, 5 Nov 2020 11:15:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CC3F916673 for ; Thu, 5 Nov 2020 11:15:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS id 4C5AA16669 for ; Thu, 5 Nov 2020 11:15:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0E8DE4601A for ; Thu, 5 Nov 2020 11:15:30 +0100 (CET) Date: Thu, 5 Nov 2020 11:15:29 +0100 From: Wolfgang Bumiller To: Dominik Csapak Cc: pbs-devel@lists.proxmox.com Message-ID: <20201105101529.6np3pkvmdpfocd7n@olga.proxmox.com> References: <20201104120938.14885-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201104120938.14885-1-d.csapak@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.011 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [daemon.rs] Subject: [pbs-devel] applied: [PATCH proxmox-backup] tools/daemon: fix reload with open connections 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: Thu, 05 Nov 2020 10:15:30 -0000 applied On Wed, Nov 04, 2020 at 01:09:38PM +0100, Dominik Csapak wrote: > instead of await'ing the result of 'create_service' directly, > poll it together with the shutdown_future > > if we reached that, fork_restart the new daemon, and await > the open future from 'create_service' > > this way the old process still handles open connections until they finish, > while we already start a new process that handles new incoming connections > > Signed-off-by: Dominik Csapak > --- > src/tools/daemon.rs | 20 +++++++++++++++++--- > 1 file changed, 17 insertions(+), 3 deletions(-) > > diff --git a/src/tools/daemon.rs b/src/tools/daemon.rs > index f4f63e7f..249ce2ad 100644 > --- a/src/tools/daemon.rs > +++ b/src/tools/daemon.rs > @@ -12,6 +12,7 @@ use std::task::{Context, Poll}; > use std::path::PathBuf; > > use anyhow::{bail, format_err, Error}; > +use futures::future::{self, Either}; > > use proxmox::tools::io::{ReadExt, WriteExt}; > > @@ -262,7 +263,7 @@ pub async fn create_daemon( > ) -> Result<(), Error> > where > F: FnOnce(tokio::net::TcpListener, NotifyReady) -> Result, > - S: Future, > + S: Future + Unpin, > { > let mut reloader = Reloader::new()?; > > @@ -271,11 +272,19 @@ where > move || async move { Ok(tokio::net::TcpListener::bind(&address).await?) }, > ).await?; > > - create_service(listener, NotifyReady)?.await; > + let server_future = create_service(listener, NotifyReady)?; > + let shutdown_future = server::shutdown_future(); > + > + let finish_future = match future::select(server_future, shutdown_future).await { > + Either::Left((_, _)) => { > + crate::tools::request_shutdown(); // make sure we are in shutdown mode > + None > + } > + Either::Right((_, server_future)) => Some(server_future), > + }; > > let mut reloader = Some(reloader); > > - crate::tools::request_shutdown(); // make sure we are in shutdown mode > if server::is_reload_request() { > log::info!("daemon reload..."); > if let Err(e) = systemd_notify(SystemdNotify::Reloading) { > @@ -288,6 +297,11 @@ where > } else { > log::info!("daemon shutting down..."); > } > + > + if let Some(future) = finish_future { > + future.await; > + } > + log::info!("daemon shut down..."); > Ok(()) > } > > -- > 2.20.1