Skip to content

Commit e5546c1

Browse files
half comments addressed
1 parent 4af4f96 commit e5546c1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/mongo_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
657657
}
658658
}
659659

660-
async _close(force = false): Promise<void> {
660+
/* @internal */
661+
private async _close(force = false): Promise<void> {
661662
// There's no way to set hasBeenClosed back to false
662663
Object.defineProperty(this.s, 'hasBeenClosed', {
663664
value: true,

test/integration/node-specific/mongo_client.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,26 @@ describe('class MongoClient', function () {
737737
).to.not.throw;
738738
});
739739
});
740+
741+
it('when connect rejects lock is released regardless', async function () {
742+
await client.connect();
743+
expect(client.topology?.isConnected()).to.be.true;
744+
745+
const closeStub = sinon.stub(client, 'close');
746+
closeStub.onFirstCall().rejects(new Error('cannot close'));
747+
748+
// first call rejected to simulate a close failure
749+
const error = await client.close().catch(error => error);
750+
expect(error).to.match(/cannot close/);
751+
752+
expect(client.topology?.isConnected()).to.be.true;
753+
closeStub.restore();
754+
755+
// second call should close
756+
await client.close();
757+
758+
expect(client.topology).to.be.undefined;
759+
});
740760
});
741761
});
742762

0 commit comments

Comments
 (0)