Skip to content

Commit

Permalink
refactor(topologies): pass errors back from selectServer
Browse files Browse the repository at this point in the history
The legacy topology types sometimes return an error, or a null
server to indicate selection failed.
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent c3bfc05 commit 097d3b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/core/topologies/mongos.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,11 @@ Mongos.prototype.selectServer = function(selector, options, callback) {
options = options || {};

const server = pickProxy(this, options.session);
if (server == null) {
callback(new MongoError('server selection failed'));
return;
}

if (this.s.debug) this.emit('pickedServer', null, server);
callback(null, server);
};
Expand Down
10 changes: 10 additions & 0 deletions lib/core/topologies/replset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,16 @@ ReplSet.prototype.selectServer = function(selector, options, callback) {
}

const server = this.s.replicaSetState.pickServer(readPreference);
if (server == null) {
callback(new MongoError('server selection failed'));
return;
}

if (!(server instanceof Server)) {
callback(server, null);
return;
}

if (this.s.debug) this.emit('pickedServer', options.readPreference, server);
callback(null, server);
};
Expand Down

0 comments on commit 097d3b9

Please sign in to comment.