From 8f8ad5607ba62223f2d004ed8a533e482de1a909 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Thu, 12 Oct 2017 12:09:53 -0400 Subject: [PATCH] fix(pool): ensure that errors are propagated on force destroy NODE-1153 --- lib/connection/pool.js | 2 +- test/tests/functional/pool_tests.js | 35 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/connection/pool.js b/lib/connection/pool.js index cc2e23b74..fe5376fdc 100644 --- a/lib/connection/pool.js +++ b/lib/connection/pool.js @@ -951,7 +951,7 @@ Pool.prototype.destroy = function(force) { while (self.queue.length > 0) { var workItem = self.queue.shift(); if (typeof workItem.cb === 'function') { - workItem.cb(null, new Error('force flushing work queue')); + workItem.cb(new MongoError('Pool was force destroyed')); } } diff --git a/test/tests/functional/pool_tests.js b/test/tests/functional/pool_tests.js index 015f7f36e..22c4e9625 100644 --- a/test/tests/functional/pool_tests.js +++ b/test/tests/functional/pool_tests.js @@ -1148,4 +1148,39 @@ describe('Pool tests', function() { pool.connect(); } }); + + it('should properly emit errors on forced destroy', { + metadata: { requires: { topology: 'single' } }, + + test: function(done) { + const pool = new Pool(null, { + host: this.configuration.host, + port: this.configuration.port, + bson: new Bson() + }); + + pool.on('connect', () => { + var query = new Query( + new Bson(), + 'system.$cmd', + { ismaster: true }, + { numberToSkip: 0, numberToReturn: 1 } + ); + + pool.write(query, function(err, result) { + expect(err).to.exist; + expect(err).to.match(/Pool was force destroyed/); + expect(result).to.not.exist; + + expect(Object.keys(Connection.connections())).to.have.length(0); + Connection.disableConnectionAccounting(); + done(); + }); + + pool.destroy({ force: true }); + }); + + pool.connect(); + } + }); });