From 82e368d0658fbadf9188475e9bd9c3acaf932b9c Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Fri, 29 Dec 2023 07:50:28 -0500 Subject: [PATCH] Close connections from pool in serial --- src/client.rs | 3 ++- src/pool.rs | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index c318d1c..ad48b50 100644 --- a/src/client.rs +++ b/src/client.rs @@ -230,7 +230,7 @@ impl Client { // If the worker thread has already shut down, return Ok here. return Ok(()); } - // If receiving fails, the + // If receiving fails, the connection is already closed. rx.await.unwrap_or(Ok(())) } @@ -273,6 +273,7 @@ impl Client { if self.conn_tx.send(Command::Shutdown(func)).is_err() { return Ok(()); } + // If receiving fails, the connection is already closed. rx.recv().unwrap_or(Ok(())) } } diff --git a/src/pool.rs b/src/pool.rs index 0da9eb6..e80c48d 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -197,11 +197,10 @@ impl Pool { /// After this method returns, all calls to `self::conn()` or /// `self::conn_mut()` will return an [`Error::Closed`] error. pub async fn close(&self) -> Result<(), Error> { - let futures = self.state.clients.iter().map(|client| client.close()); - join_all(futures) - .await - .into_iter() - .collect::>() + for client in self.state.clients.iter() { + client.close().await?; + } + Ok(()) } /// Invokes the provided function with a [`rusqlite::Connection`], blocking @@ -232,7 +231,7 @@ impl Pool { self.state .clients .iter() - .try_for_each(|client| client.clone().close_blocking()) + .try_for_each(|client| client.close_blocking()) } fn get(&self) -> &Client {