Skip to content

Commit 46f0378

Browse files
committed
Revert parallel close_blocking
1 parent a987eae commit 46f0378

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ impl Pool {
197197
/// After this method returns, all calls to `self::conn()` or
198198
/// `self::conn_mut()` will return an [`Error::Closed`] error.
199199
pub async fn close(&self) -> Result<(), Error> {
200-
for client in self.state.clients.iter() {
201-
client.close().await?;
202-
}
200+
let closes = self.state.clients.iter().map(|client| client.close());
201+
let res = join_all(closes).await;
202+
res.into_iter().collect::<Result<Vec<_>, Error>>()?;
203203
Ok(())
204204
}
205205

tests/tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async_test!(test_journal_mode);
8484
async_test!(test_concurrency);
8585
async_test!(test_pool);
8686
async_test!(test_pool_conn_for_each);
87+
async_test!(test_pool_close_concurrent);
8788

8889
async fn test_journal_mode() {
8990
let tmp_dir = tempfile::tempdir().unwrap();
@@ -227,3 +228,24 @@ async fn test_pool_conn_for_each() {
227228
// cleanup
228229
pool.close().await.expect("closing client conn");
229230
}
231+
232+
async fn test_pool_close_concurrent() {
233+
let tmp_dir = tempfile::tempdir().unwrap();
234+
let pool = PoolBuilder::new()
235+
.path(tmp_dir.path().join("sqlite.db"))
236+
.num_conns(2)
237+
.open()
238+
.await
239+
.expect("pool unable to be opened");
240+
241+
let c1 = pool.close();
242+
let c2 = pool.close();
243+
futures_util::future::join_all([c1, c2])
244+
.await
245+
.into_iter()
246+
.collect::<Result<Vec<_>, Error>>()
247+
.expect("closing concurrently");
248+
249+
let res = pool.conn(|c| c.execute("SELECT 1", ())).await;
250+
assert!(matches!(res, Err(Error::Closed)));
251+
}

0 commit comments

Comments
 (0)