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 815B162C88 for ; Thu, 1 Oct 2020 11:38:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7306D1FDE6 for ; Thu, 1 Oct 2020 11:38:50 +0200 (CEST) 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 D6F9F1FDDE for ; Thu, 1 Oct 2020 11:38:49 +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 9889F45992 for ; Thu, 1 Oct 2020 11:38:49 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Thu, 1 Oct 2020 11:38:42 +0200 Message-Id: <20201001093842.394-1-s.reiter@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.045 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 Subject: [pbs-devel] [PATCH proxmox-backup] ParallelHandler: check for errors during thread join 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, 01 Oct 2020 09:38:50 -0000 Fix a potential bug where errors that happen after the SendHandle has been dropped while doing the thread join might have been ignored. Requires internal check_abort to be moved out of 'impl SendHandle' since we only have the Mutex left, not the SendHandle. Signed-off-by: Stefan Reiter --- Extracted from previous RFC series. src/tools/parallel_handler.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs index f1d9adec..185ac2fc 100644 --- a/src/tools/parallel_handler.rs +++ b/src/tools/parallel_handler.rs @@ -10,19 +10,19 @@ pub struct SendHandle { abort: Arc>>, } -impl SendHandle { - /// Returns the first error happened, if any - pub fn check_abort(&self) -> Result<(), Error> { - let guard = self.abort.lock().unwrap(); - if let Some(err_msg) = &*guard { - return Err(format_err!("{}", err_msg)); - } - Ok(()) +/// Returns the first error happened, if any +pub fn check_abort(abort: Arc>>) -> Result<(), Error> { + let guard = abort.lock().unwrap(); + if let Some(err_msg) = &*guard { + return Err(format_err!("{}", err_msg)); } + Ok(()) +} +impl SendHandle { /// Send data to the worker threads pub fn send(&self, input: I) -> Result<(), Error> { - self.check_abort()?; + check_abort(Arc::clone(&self.abort))?; match self.input.send(input) { Ok(()) => Ok(()), Err(_) => bail!("send failed - channel closed"), @@ -121,12 +121,16 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> { /// Wait for worker threads to complete and check for errors pub fn complete(mut self) -> Result<(), Error> { - self.input.as_ref().unwrap().check_abort()?; - drop(self.input.take()); + let input = self.input.take().unwrap(); + let abort = Arc::clone(&input.abort); + check_abort(Arc::clone(&abort))?; + drop(input); let msg_list = self.join_threads(); if msg_list.is_empty() { + // an error might be encountered while waiting for the join + check_abort(abort)?; return Ok(()); } Err(format_err!("{}", msg_list.join("\n"))) -- 2.20.1