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

[Ported] fix(connection): default family to undefined rather than 4 #240

Merged
merged 3 commits into from
Nov 21, 2017
Merged
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
16 changes: 11 additions & 5 deletions lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var connections = {};
* @class
* @param {string} options.host The server host
* @param {number} options.port The server port
* @param {number} [options.family=4] Version of IP stack. Defaults to 4.
* @param {number} [options.family=null] IP version for DNS lookup, passed down to Node's [`dns.lookup()` function](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback). If set to `6`, will only look for ipv6 addresses.
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
* @param {number} [options.keepAliveInitialDelay=300000] Initial delay before TCP keep alive enabled
* @param {boolean} [options.noDelay=true] TCP Connection no delay
Expand Down Expand Up @@ -104,7 +104,7 @@ var Connection = function(messageHandler, options) {
// Default options
this.port = options.port || 27017;
this.host = options.host || 'localhost';
this.family = typeof options.family === 'number' ? options.family : 4;
this.family = typeof options.family === 'number' ? options.family : void 0;
this.keepAlive = typeof options.keepAlive === 'boolean' ? options.keepAlive : true;
this.keepAliveInitialDelay =
typeof options.keepAliveInitialDelay === 'number' ? options.keepAliveInitialDelay : 300000;
Expand Down Expand Up @@ -542,9 +542,15 @@ Connection.prototype.connect = function(_options) {
}

// Create new connection instance
var connection_options = self.domainSocket
? { path: self.host }
: { port: self.port, host: self.host, family: self.family };
var connection_options;
if (self.domainSocket) {
connection_options = { path: self.host };
} else {
connection_options = { port: self.port, host: self.host };
if (self.family !== void 0) {
connection_options.family = self.family;
}
}
self.connection = net.createConnection(connection_options);

// Set the options for the connection
Expand Down