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 @@ -197,9 +197,9 @@ impl Pool {
197
197
/// After this method returns, all calls to `self::conn()` or
198
198
/// `self::conn_mut()` will return an [`Error::Closed`] error.
199
199
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 > > ( ) ? ;
203
203
Ok ( ( ) )
204
204
}
205
205
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ async_test!(test_journal_mode);
84
84
async_test ! ( test_concurrency) ;
85
85
async_test ! ( test_pool) ;
86
86
async_test ! ( test_pool_conn_for_each) ;
87
+ async_test ! ( test_pool_close_concurrent) ;
87
88
88
89
async fn test_journal_mode ( ) {
89
90
let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
@@ -227,3 +228,24 @@ async fn test_pool_conn_for_each() {
227
228
// cleanup
228
229
pool. close ( ) . await . expect ( "closing client conn" ) ;
229
230
}
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
+ }
You can’t perform that action at this time.
0 commit comments