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.
This commit is contained in:
Brian M. Carlson 2014-10-17 23:09:55 -04:00
parent e7e5f1c331
commit 89d0938655

View File

@ -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();
});