File tree 2 files changed +13
-5
lines changed
test/integration/node-specific
2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -504,10 +504,14 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
504
504
return ;
505
505
}
506
506
507
+ // clear out references to old topology
508
+ const topology = this . topology ;
509
+ this . topology = undefined ;
510
+
507
511
// If we would attempt to select a server and get nothing back we short circuit
508
512
// to avoid the server selection timeout.
509
513
const selector = readPreferenceServerSelector ( ReadPreference . primaryPreferred ) ;
510
- const topologyDescription = this . topology . description ;
514
+ const topologyDescription = topology . description ;
511
515
const serverDescriptions = Array . from ( topologyDescription . servers . values ( ) ) ;
512
516
const servers = selector ( topologyDescription , serverDescriptions ) ;
513
517
if ( servers . length !== 0 ) {
@@ -522,10 +526,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
522
526
}
523
527
}
524
528
525
- // clear out references to old topology
526
- const topology = this . topology ;
527
- this . topology = undefined ;
528
-
529
529
await new Promise < void > ( ( resolve , reject ) => {
530
530
topology . close ( { force } , error => {
531
531
if ( error ) return reject ( error ) ;
Original file line number Diff line number Diff line change @@ -385,6 +385,14 @@ describe('class MongoClient', function () {
385
385
}
386
386
} ) ;
387
387
388
+ it ( 'it can call close() concurrently' , async function ( ) {
389
+ const client = this . configuration . newClient ( ) ;
390
+ await client . connect ( ) ;
391
+ // Ensure topology is opened before trying to close
392
+ await client . db ( ) . command ( { hello : 1 } ) ;
393
+ await Promise . all ( [ client . close ( ) , client . close ( ) ] ) ;
394
+ } ) ;
395
+
388
396
context ( 'explict #connect()' , ( ) => {
389
397
let client : MongoClient ;
390
398
beforeEach ( function ( ) {
You can’t perform that action at this time.
0 commit comments