Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(pool): ensure that errors are propagated on force destroy
Browse files Browse the repository at this point in the history
NODE-1153
  • Loading branch information
mbroadst committed Oct 12, 2017
1 parent 31ef03a commit 8f8ad56
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/tests/functional/pool_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});

0 comments on commit 8f8ad56

Please sign in to comment.