Skip to content

Commit ba76696

Browse files
authored
Revert "fix: allow client connect after close (#2581)" (#2591)
This reverts commit 1aecf96.
1 parent 16d6572 commit ba76696

File tree

4 files changed

+5
-51
lines changed

4 files changed

+5
-51
lines changed

src/mongo_client.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,29 +352,19 @@ export class MongoClient extends EventEmitter implements OperationParent {
352352
const force = typeof forceOrCallback === 'boolean' ? forceOrCallback : false;
353353

354354
return maybePromise(callback, cb => {
355-
const completeClose = (err?: AnyError) => {
356-
// clear out references to old topology
357-
this.topology = undefined;
358-
this.s.dbCache = new Map();
359-
this.s.sessions = new Set();
360-
361-
cb(err);
362-
};
363-
364355
if (this.topology == null) {
365-
completeClose();
366-
return;
356+
return cb();
367357
}
368358

369359
const topology = this.topology;
370360
topology.close({ force }, err => {
371361
const autoEncrypter = topology.s.options.autoEncrypter;
372362
if (!autoEncrypter) {
373-
completeClose(err);
363+
cb(err);
374364
return;
375365
}
376366

377-
autoEncrypter.teardown(force, err2 => completeClose(err || err2));
367+
autoEncrypter.teardown(force, err2 => cb(err || err2));
378368
});
379369
});
380370
}

src/operations/connect.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ export function connect(
197197
throw new Error('no callback function provided');
198198
}
199199

200-
// Has a connection already been established?
201-
if (mongoClient.topology && mongoClient.topology.isConnected()) {
202-
throw new MongoError(`'connect' cannot be called when already connected`);
203-
}
204-
205200
let didRequestAuthentication = false;
206201
const logger = new Logger('MongoClient', options);
207202

test/functional/connection.test.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const test = require('./shared').assert,
33
setupDatabase = require('./shared').setupDatabase,
44
expect = require('chai').expect;
5-
const withClient = require('./shared').withClient;
65

76
describe('Connection', function () {
87
before(function () {
@@ -274,34 +273,4 @@ describe('Connection', function () {
274273
done();
275274
}
276275
});
277-
278-
it(
279-
'should be able to connect again after close',
280-
withClient(function (client, done) {
281-
expect(client.isConnected()).to.be.true;
282-
283-
const collection = () => client.db('testReconnect').collection('test');
284-
collection().insertOne({ a: 1 }, (err, result) => {
285-
expect(err).to.not.exist;
286-
expect(result).to.exist;
287-
288-
client.close(err => {
289-
expect(err).to.not.exist;
290-
expect(client.isConnected()).to.be.false;
291-
292-
client.connect(err => {
293-
expect(err).to.not.exist;
294-
expect(client.isConnected()).to.be.true;
295-
296-
collection().insertOne({ b: 2 }, (err, result) => {
297-
expect(err).to.not.exist;
298-
expect(result).to.exist;
299-
expect(client.topology.isDestroyed()).to.be.false;
300-
done();
301-
});
302-
});
303-
});
304-
});
305-
})
306-
);
307276
});

test/functional/sessions.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('Sessions', function () {
123123
// verify that the `endSessions` command was sent
124124
const lastCommand = test.commands.started[test.commands.started.length - 1];
125125
expect(lastCommand.commandName).to.equal('endSessions');
126-
expect(client.topology).to.not.exist;
126+
expect(client.topology.s.sessionPool.sessions).to.have.length(0);
127127
});
128128
});
129129
});
@@ -143,7 +143,7 @@ describe('Sessions', function () {
143143
// verify that the `endSessions` command was sent
144144
const lastCommand = test.commands.started[test.commands.started.length - 1];
145145
expect(lastCommand.commandName).to.equal('endSessions');
146-
expect(client.topology).to.not.exist;
146+
expect(client.topology.s.sessionPool.sessions).to.have.length(0);
147147
});
148148
});
149149
}

0 commit comments

Comments
 (0)