File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -204,9 +204,9 @@ impl Pool {
204204 /// After this method returns, all calls to `self::conn()` or
205205 /// `self::conn_mut()` will return an [`Error::Closed`] error.
206206 pub async fn close ( & self ) -> Result < ( ) , Error > {
207- for client in self . state . clients . iter ( ) {
208- client . close ( ) . await ? ;
209- }
207+ let closes = self . state . clients . iter ( ) . map ( |client| client . close ( ) ) ;
208+ let res = join_all ( closes ) . await ;
209+ res . into_iter ( ) . collect :: < Result < Vec < _ > , Error > > ( ) ? ;
210210 Ok ( ( ) )
211211 }
212212
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ async_test!(test_journal_mode);
8484async_test ! ( test_concurrency) ;
8585async_test ! ( test_pool) ;
8686async_test ! ( test_pool_conn_for_each) ;
87+ async_test ! ( test_pool_close_concurrent) ;
8788async_test ! ( test_pool_num_conns_zero_clamps) ;
8889
8990async fn test_journal_mode ( ) {
@@ -229,6 +230,27 @@ async fn test_pool_conn_for_each() {
229230 pool. close ( ) . await . expect ( "closing client conn" ) ;
230231}
231232
233+ async fn test_pool_close_concurrent ( ) {
234+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
235+ let pool = PoolBuilder :: new ( )
236+ . path ( tmp_dir. path ( ) . join ( "sqlite.db" ) )
237+ . num_conns ( 2 )
238+ . open ( )
239+ . await
240+ . expect ( "pool unable to be opened" ) ;
241+
242+ let c1 = pool. close ( ) ;
243+ let c2 = pool. close ( ) ;
244+ futures_util:: future:: join_all ( [ c1, c2] )
245+ . await
246+ . into_iter ( )
247+ . collect :: < Result < Vec < _ > , Error > > ( )
248+ . expect ( "closing concurrently" ) ;
249+
250+ let res = pool. conn ( |c| c. execute ( "SELECT 1" , ( ) ) ) . await ;
251+ assert ! ( matches!( res, Err ( Error :: Closed ) ) ) ;
252+ }
253+
232254async fn test_pool_num_conns_zero_clamps ( ) {
233255 let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
234256 let pool = PoolBuilder :: new ( )
You can’t perform that action at this time.
0 commit comments