From eb2786f39c553867533bcdd5af4400d6d791c515 Mon Sep 17 00:00:00 2001 From: Hana Pearlman Date: Tue, 20 Oct 2020 15:44:49 -0400 Subject: [PATCH] Revert "fix: allow client connect after close (#2581)" This reverts commit 1aecf964d79344acea4ff4387d2faf51b78cfe78. --- src/mongo_client.ts | 16 +++------------ src/operations/connect.ts | 5 ----- test/functional/connection.test.js | 31 ------------------------------ test/functional/sessions.test.js | 4 ++-- 4 files changed, 5 insertions(+), 51 deletions(-) diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 2ede2f64d2b..c5a275f8636 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -349,29 +349,19 @@ export class MongoClient extends EventEmitter implements OperationParent { const force = typeof forceOrCallback === 'boolean' ? forceOrCallback : false; return maybePromise(callback, cb => { - const completeClose = (err?: AnyError) => { - // clear out references to old topology - this.topology = undefined; - this.s.dbCache = new Map(); - this.s.sessions = new Set(); - - cb(err); - }; - if (this.topology == null) { - completeClose(); - return; + return cb(); } const topology = this.topology; topology.close({ force }, err => { const autoEncrypter = topology.s.options.autoEncrypter; if (!autoEncrypter) { - completeClose(err); + cb(err); return; } - autoEncrypter.teardown(force, err2 => completeClose(err || err2)); + autoEncrypter.teardown(force, err2 => cb(err || err2)); }); }); } diff --git a/src/operations/connect.ts b/src/operations/connect.ts index c99e5c81b08..85700deb640 100644 --- a/src/operations/connect.ts +++ b/src/operations/connect.ts @@ -197,11 +197,6 @@ export function connect( throw new Error('no callback function provided'); } - // Has a connection already been established? - if (mongoClient.topology && mongoClient.topology.isConnected()) { - throw new MongoError(`'connect' cannot be called when already connected`); - } - let didRequestAuthentication = false; const logger = new Logger('MongoClient', options); diff --git a/test/functional/connection.test.js b/test/functional/connection.test.js index 79497eb18d7..59e46c7e9cb 100644 --- a/test/functional/connection.test.js +++ b/test/functional/connection.test.js @@ -2,7 +2,6 @@ const test = require('./shared').assert, setupDatabase = require('./shared').setupDatabase, expect = require('chai').expect; -const withClient = require('./shared').withClient; describe('Connection', function () { before(function () { @@ -274,34 +273,4 @@ describe('Connection', function () { done(); } }); - - it( - 'should be able to connect again after close', - withClient(function (client, done) { - expect(client.isConnected()).to.be.true; - - const collection = () => client.db('testReconnect').collection('test'); - collection().insertOne({ a: 1 }, (err, result) => { - expect(err).to.not.exist; - expect(result).to.exist; - - client.close(err => { - expect(err).to.not.exist; - expect(client.isConnected()).to.be.false; - - client.connect(err => { - expect(err).to.not.exist; - expect(client.isConnected()).to.be.true; - - collection().insertOne({ b: 2 }, (err, result) => { - expect(err).to.not.exist; - expect(result).to.exist; - expect(client.topology.isDestroyed()).to.be.false; - done(); - }); - }); - }); - }); - }) - ); }); diff --git a/test/functional/sessions.test.js b/test/functional/sessions.test.js index eb25a46ec87..2751019bfb9 100644 --- a/test/functional/sessions.test.js +++ b/test/functional/sessions.test.js @@ -123,7 +123,7 @@ describe('Sessions', function () { // verify that the `endSessions` command was sent const lastCommand = test.commands.started[test.commands.started.length - 1]; expect(lastCommand.commandName).to.equal('endSessions'); - expect(client.topology).to.not.exist; + expect(client.topology.s.sessionPool.sessions).to.have.length(0); }); }); }); @@ -143,7 +143,7 @@ describe('Sessions', function () { // verify that the `endSessions` command was sent const lastCommand = test.commands.started[test.commands.started.length - 1]; expect(lastCommand.commandName).to.equal('endSessions'); - expect(client.topology).to.not.exist; + expect(client.topology.s.sessionPool.sessions).to.have.length(0); }); }); }