diff --git a/Cargo.lock b/Cargo.lock index c24d2ff8fa..f34884628e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3582,7 +3582,6 @@ dependencies = [ "rust_decimal", "rustls", "rustls-native-certs", - "rustls-pki-types", "serde", "serde_json", "sha2", diff --git a/examples/postgres/listen/src/main.rs b/examples/postgres/listen/src/main.rs index b9ed35ba4b..9f56e91f90 100644 --- a/examples/postgres/listen/src/main.rs +++ b/examples/postgres/listen/src/main.rs @@ -68,6 +68,10 @@ async fn main() -> Result<(), Box> { } } + // The stream is holding one connection. It needs to be dropped to allow the connection to + // return to the pool, otherwise `pool.close()` would never return. + drop(stream); + pool.close().await; Ok(()) diff --git a/sqlx-core/src/pool/inner.rs b/sqlx-core/src/pool/inner.rs index 2066364a8e..f0c8101690 100644 --- a/sqlx-core/src/pool/inner.rs +++ b/sqlx-core/src/pool/inner.rs @@ -98,19 +98,14 @@ impl PoolInner { self.mark_closed(); async move { - for permits in 1..=self.options.max_connections { - // Close any currently idle connections in the pool. - while let Some(idle) = self.idle_conns.pop() { - let _ = idle.live.float((*self).clone()).close().await; - } - - if self.size() == 0 { - break; - } + let _permits = self.semaphore.acquire(self.options.max_connections).await; - // Wait for all permits to be released. - let _permits = self.semaphore.acquire(permits).await; + while let Some(idle) = self.idle_conns.pop() { + let _ = idle.live.raw.close().await; } + + self.num_idle.store(0, Ordering::Release); + self.size.store(0, Ordering::Release); } }