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 {
204
204
/// After this method returns, all calls to `self::conn()` or
205
205
/// `self::conn_mut()` will return an [`Error::Closed`] error.
206
206
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 > > ( ) ? ;
210
210
Ok ( ( ) )
211
211
}
212
212
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
async_test ! ( test_pool_num_conns_zero_clamps) ;
88
89
89
90
async fn test_journal_mode ( ) {
@@ -229,6 +230,27 @@ async fn test_pool_conn_for_each() {
229
230
pool. close ( ) . await . expect ( "closing client conn" ) ;
230
231
}
231
232
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
+
232
254
async fn test_pool_num_conns_zero_clamps ( ) {
233
255
let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
234
256
let pool = PoolBuilder :: new ( )
You can’t perform that action at this time.
0 commit comments