Skip to content

Commit ed015f9

Browse files
committed
Fix Unix domain socket setting.
This code was misconceived in that the host parameter for a Unix domain socket connection must point to the directory containing the socket, and not to the socket itself. Libpq will look for the socket based on the host and port settings. See <http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS>
1 parent 69b4171 commit ed015f9

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

lib/connection-parameters.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
5858
params.push("dbname='" + this.database + "'");
5959
}
6060
if(this.isDomainSocket) {
61-
params.push("host=" + this.getDomainSocketName());
61+
params.push("host=" + this.host);
6262
return cb(null, params.join(' '));
6363
}
6464
params.push("options=--client_encoding='utf-8'");
@@ -69,14 +69,4 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
6969
});
7070
};
7171

72-
ConnectionParameters.prototype.getDomainSocketName = function() {
73-
var filename = '.s.PGSQL.' + this.port;
74-
75-
//if host is full path to socket fd with port number, just return it
76-
if(this.host.indexOf(filename) > -1) return this.host;
77-
78-
//otherwise, build it from host + standard filename + port
79-
return path.join(this.host, filename);
80-
};
81-
8272
module.exports = ConnectionParameters;

test/unit/connection-parameters/creation-tests.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ test('initializing with unix domain socket', function() {
5353
assert.equal(subject.host, '/var/run/');
5454
});
5555

56-
test('builds domain socket', function() {
57-
var subject = new ConnectionParameters({
58-
host: '/var/run/',
59-
port: 1234
60-
});
61-
assert.equal(subject.getDomainSocketName(), '/var/run/.s.PGSQL.1234');
62-
subject.host = '/tmp';
63-
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
64-
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
65-
});
66-
6756
test('libpq connection string building', function() {
6857
var checkForPart = function(array, part) {
6958
assert.ok(array.indexOf(part) > -1, array.join(" ") + " did not contain " + part);
@@ -131,7 +120,7 @@ test('libpq connection string building', function() {
131120
assert.isNull(err);
132121
var parts = constring.split(" ");
133122
checkForPart(parts, "user='brian'");
134-
checkForPart(parts, "host=/tmp/.s.PGSQL.5432");
123+
checkForPart(parts, "host=/tmp/");
135124
}));
136125
});
137126

0 commit comments

Comments
 (0)