From 67ea461c7ea694af1f01b95744d38fa044d0ee10 Mon Sep 17 00:00:00 2001 From: Jonathan Rudenberg Date: Tue, 24 Apr 2018 20:58:13 -0400 Subject: [PATCH] Don't call connect until connect handler is set up If a stream is specified, the connect event will be emitted immediately. --- lib/client.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/client.js b/lib/client.js index 3228571d5..e6779f25f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -65,12 +65,6 @@ Client.prototype.connect = function (callback) { } this._connecting = true - if (this.host && this.host.indexOf('/') === 0) { - con.connect(this.host + '/.s.PGSQL.' + this.port) - } else { - con.connect(this.port, this.host) - } - // once connection is established send startup message con.on('connect', function () { if (self.ssl) { @@ -194,6 +188,12 @@ Client.prototype.connect = function (callback) { self.emit('notice', msg) }) + if (this.host && this.host.indexOf('/') === 0) { + con.connect(this.host + '/.s.PGSQL.' + this.port) + } else { + con.connect(this.port, this.host) + } + if (!callback) { return new global.Promise((resolve, reject) => { this.once('error', reject)