Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-5155) release connection lock when topology closed #3618

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
topology.client = this;

topology.once(Topology.OPEN, () => this.emit('open', this));
topology.on(Topology.TOPOLOGY_CLOSED, () => {
this.connectionLock = undefined;
});

for (const event of MONGO_CLIENT_EVENTS) {
topology.on(event, (...args: any[]) => this.emit(event, ...(args as any)));
Expand Down
10 changes: 10 additions & 0 deletions test/integration/node-specific/mongo_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,16 @@ describe('class MongoClient', function () {
expect(topologyOpenEvents).to.have.lengthOf(1);
expect(client.topology?.isConnected()).to.be.true;
});

it('releases the lock if the topology is closed before connection is complete', function (done) {
clientConnect();
client.close();
client.once('topologyClosed', async () => {
await clientConnect();
expect(client.topology?.isConnected()).to.be.true;
done();
});
});
});

context('#close()', () => {
Expand Down