Skip to content

Commit 28eeda3

Browse files
added suggested connection dependency fix
1 parent b9a588b commit 28eeda3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/mongo_client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { MONGO_CLIENT_EVENTS } from './constants';
2121
import { type AbstractCursor } from './cursor/abstract_cursor';
2222
import { Db, type DbOptions } from './db';
2323
import type { Encrypter } from './encrypter';
24-
import { MongoInvalidArgumentError } from './error';
24+
import { MongoInvalidArgumentError, MongoRuntimeError } from './error';
2525
import { MongoClientAuthProviders } from './mongo_client_auth_providers';
2626
import {
2727
type LogComponentSeveritiesClientOptions,
@@ -538,6 +538,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
538538
* @see docs.mongodb.org/manual/reference/connection-string/
539539
*/
540540
async connect(): Promise<this> {
541+
if (this.closeLock) {
542+
throw new MongoRuntimeError('Client cannot be connected while close() is in progress.');
543+
}
544+
541545
if (this.connectionLock) {
542546
return await this.connectionLock;
543547
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ describe('class MongoClient', function () {
762762

763763
context('concurrent calls', () => {
764764
let topologyClosedSpy;
765+
765766
beforeEach(async function () {
766767
await client.connect();
767768
const coll = client.db('db').collection('concurrentCalls');
@@ -820,6 +821,8 @@ describe('class MongoClient', function () {
820821
await client.close();
821822

822823
expect(client.topology).to.be.undefined;
824+
});
825+
});
823826

824827
describe('active cursors', function () {
825828
let collection: Collection<{ _id: number }>;

0 commit comments

Comments
 (0)