Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ Pool.prototype.capConnections = function(maxConnections) {
var connections = this.connections.slice(maxConnections);
// Cap the active connections
this.connections = this.connections.slice(0, maxConnections);

if (this.index >= maxConnections){
// Go back to the beggining of the pool if capping connections
this.index = 0;
}

// Remove all listeners
for(var i = 0; i < connections.length; i++) {
connections[i].removeAllListeners('close');
Expand Down
3 changes: 2 additions & 1 deletion lib/topologies/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ var executeSingleOperation = function(self, ns, cmd, queryOptions, options, onAl
var connection = options.connection || self.s.pool.get();

// Double check if we have a valid connection
if(!connection.isConnected()) {
// Checking that the connection exists to avoid an uncaught exception in case there is an issue with the pool
if(!(connection && connection.isConnected())) {
return callback(new MongoError(f("no connection available to server %s", self.name)));
}

Expand Down