From 89d09386556750f3af60b87960503d88a8954e42 Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Fri, 17 Oct 2014 23:09:55 -0400 Subject: [PATCH] Subscribe to notification before emitting connected Fixes a case where you connect & immediatley disconnect and _sometimes_ your notification subscription starts the reader on the libpq instance after the libpq instance is disconnected. This segfaults the app. --- lib/native/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/native/index.js b/lib/native/index.js index 1b79488e..dd708be0 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -51,8 +51,6 @@ Client.prototype.connect = function(cb) { //set internal states to connected self._connected = true; - self.emit('connect'); - self._pulseQueryQueue(true); //handle connection errors from the native layer self.native.on('error', function(err) { @@ -70,6 +68,10 @@ Client.prototype.connect = function(cb) { }); }); + //signal we are connected now + self.emit('connect'); + self._pulseQueryQueue(true); + //possibly call the optional callback if(cb) cb(); });