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

Commit

Permalink
feat(server-check): reintroduce server version check
Browse files Browse the repository at this point in the history
NODE-1085
  • Loading branch information
mbroadst committed Aug 7, 2017
1 parent e4f1786 commit 486aace
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/topologies/server.js
Expand Up @@ -172,6 +172,12 @@ Object.defineProperty(Server.prototype, 'name', {
get: function() { return this.s.options.host + ":" + this.s.options.port; }
});

function isSupportedServer(response) {
return response &&
typeof response.maxWireVersion === 'number' &&
response.maxWireVersion >= 2;
}

function configureWireProtocolHandler(self, ismaster) {
// 3.2 wire protocol handler
if (ismaster.maxWireVersion >= 4) {
Expand Down Expand Up @@ -254,10 +260,14 @@ var eventHandler = function(self, event) {
}, function(err, result) {
// Set initial lastIsMasterMS
self.lastIsMasterMS = new Date().getTime() - start;
if(err) {
if (err) {
self.destroy();
return self.emit('error', err);
}

if (!isSupportedServer(result.result)) {
self.destroy();
if(self.listeners('error').length > 0) self.emit('error', err);
return;
return self.emit('error', new MongoError('unsupported server version'), self);
}

// Determine whether the server is instructing us to use a compressor
Expand Down

0 comments on commit 486aace

Please sign in to comment.