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 5DE22713A3 for ; Sat, 2 Oct 2021 11:54:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4D6FDB3BA for ; Sat, 2 Oct 2021 11:54:07 +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 4F1C2B3AC for ; Sat, 2 Oct 2021 11:54:06 +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 1A93245405 for ; Sat, 2 Oct 2021 11:54:00 +0200 (CEST) Message-ID: Date: Sat, 2 Oct 2021 11:52:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Thunderbird/93.0 Content-Language: en-US To: Proxmox Backup Server development discussion , Dominik Csapak References: <20210930071858.1116527-1-d.csapak@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20210930071858.1116527-1-d.csapak@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.230 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-backup-api.rs, daemon.rs, proxmox-backup-proxy.rs, minimal-rest-server.rs] Subject: [pbs-devel] applied: [PATCH proxmox-backup] rest-server/daemon: use sd_notify_barrier for service reloading 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: Sat, 02 Oct 2021 09:54:07 -0000 On 30.09.21 09:18, Dominik Csapak wrote: > until now, we manually polled the systemd service state during a reload > so that the sd_notify messages get processed in the correct order > (RELOAD(old) -> MAINPID(old) -> READY(new)) > > with systemd >= 246 there is now 'sd_notify_barrier' which > blocks until systemd processed all prior messages > > with that change, the daemon does not need to know the service name anymore > > Signed-off-by: Dominik Csapak > --- > debian/control | 2 +- > .../examples/minimal-rest-server.rs | 1 - > proxmox-rest-server/src/daemon.rs | 61 +++++++------------ > src/bin/proxmox-backup-api.rs | 1 - > src/bin/proxmox-backup-proxy.rs | 1 - > 5 files changed, 22 insertions(+), 44 deletions(-) > applied, thanks! made a few followups, see inline. > @@ -248,7 +251,6 @@ impl Reloadable for tokio::net::TcpListener { > pub async fn create_daemon( > address: std::net::SocketAddr, > create_service: F, > - service_name: &str, > ) -> Result<(), Error> > where > F: FnOnce(tokio::net::TcpListener) -> Result, > @@ -289,7 +291,10 @@ where > if let Err(e) = systemd_notify(SystemdNotify::Reloading) { > log::error!("failed to notify systemd about the state change: {}", e); > } > - wait_service_is_state(service_name, "reloading").await?; I added a comment here to actually give an answer to why-reason. > + if let Err(e) = systemd_notify_barrier() { > + log::error!("failed to wait on systemd-processing: {}", e); > + } > + > if let Err(e) = reloader.take().unwrap().fork_restart() { > log::error!("error during reload: {}", e); > let _ = systemd_notify(SystemdNotify::Status("error during reload".to_string())); > #[link(name = "systemd")] > extern "C" { > fn sd_notify(unset_environment: c_int, state: *const c_char) -> c_int; > + fn sd_notify_barrier(unset_environment: c_int, timeout: u64) -> c_int; > } > > /// Systemd sercice startup states (see: ``man sd_notify``) > @@ -358,6 +326,19 @@ pub enum SystemdNotify { > MainPid(nix::unistd::Pid), > } > > +/// Waits until all previously sent messages with sd_notify are processed > +pub fn systemd_notify_barrier() -> Result<(), Error> { > + let rc = unsafe { sd_notify_barrier(0, u64::MAX) }; // infinite timeout I exposed the timeout to the caller, making it act more like the thin FFI wrapper it is. > + if rc < 0 { > + bail!( > + "systemd_notify_barrier failed: {}", > + std::io::Error::from_raw_os_error(-rc), > + ); > + } > + > + Ok(()) > +} > + this was barging in between the SystemdNotify enum that is explicitly for, well systemd_notify below, while not using that itself -> so I moved it out of the way. > /// Tells systemd the startup state of the service (see: ``man sd_notify``) > pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> { >