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

Commit 8f8ad56

Browse files
committed
fix(pool): ensure that errors are propagated on force destroy
NODE-1153
1 parent 31ef03a commit 8f8ad56

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/connection/pool.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ Pool.prototype.destroy = function(force) {
951951
while (self.queue.length > 0) {
952952
var workItem = self.queue.shift();
953953
if (typeof workItem.cb === 'function') {
954-
workItem.cb(null, new Error('force flushing work queue'));
954+
workItem.cb(new MongoError('Pool was force destroyed'));
955955
}
956956
}
957957

test/tests/functional/pool_tests.js

+35
Original file line numberDiff line numberDiff line change
@@ -1148,4 +1148,39 @@ describe('Pool tests', function() {
11481148
pool.connect();
11491149
}
11501150
});
1151+
1152+
it('should properly emit errors on forced destroy', {
1153+
metadata: { requires: { topology: 'single' } },
1154+
1155+
test: function(done) {
1156+
const pool = new Pool(null, {
1157+
host: this.configuration.host,
1158+
port: this.configuration.port,
1159+
bson: new Bson()
1160+
});
1161+
1162+
pool.on('connect', () => {
1163+
var query = new Query(
1164+
new Bson(),
1165+
'system.$cmd',
1166+
{ ismaster: true },
1167+
{ numberToSkip: 0, numberToReturn: 1 }
1168+
);
1169+
1170+
pool.write(query, function(err, result) {
1171+
expect(err).to.exist;
1172+
expect(err).to.match(/Pool was force destroyed/);
1173+
expect(result).to.not.exist;
1174+
1175+
expect(Object.keys(Connection.connections())).to.have.length(0);
1176+
Connection.disableConnectionAccounting();
1177+
done();
1178+
});
1179+
1180+
pool.destroy({ force: true });
1181+
});
1182+
1183+
pool.connect();
1184+
}
1185+
});
11511186
});

0 commit comments

Comments
 (0)