File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
test/integration/node-specific Expand file tree Collapse file tree 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> {
504504 return ;
505505 }
506506
507+ // clear out references to old topology
508+ const topology = this . topology ;
509+ this . topology = undefined ;
510+
507511 // If we would attempt to select a server and get nothing back we short circuit
508512 // to avoid the server selection timeout.
509513 const selector = readPreferenceServerSelector ( ReadPreference . primaryPreferred ) ;
510- const topologyDescription = this . topology . description ;
514+ const topologyDescription = topology . description ;
511515 const serverDescriptions = Array . from ( topologyDescription . servers . values ( ) ) ;
512516 const servers = selector ( topologyDescription , serverDescriptions ) ;
513517 if ( servers . length !== 0 ) {
@@ -522,10 +526,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
522526 }
523527 }
524528
525- // clear out references to old topology
526- const topology = this . topology ;
527- this . topology = undefined ;
528-
529529 await new Promise < void > ( ( resolve , reject ) => {
530530 topology . close ( { force } , error => {
531531 if ( error ) return reject ( error ) ;
Original file line number Diff line number Diff line change @@ -385,6 +385,14 @@ describe('class MongoClient', function () {
385385 }
386386 } ) ;
387387
388+ 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+
388396 context ( 'explict #connect()' , ( ) => {
389397 let client : MongoClient ;
390398 beforeEach ( function ( ) {
You can’t perform that action at this time.
0 commit comments