Skip to content

Commit 89d0938

Browse files
committed
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.
1 parent e7e5f1c commit 89d0938

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/native/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ Client.prototype.connect = function(cb) {
5151

5252
//set internal states to connected
5353
self._connected = true;
54-
self.emit('connect');
55-
self._pulseQueryQueue(true);
5654

5755
//handle connection errors from the native layer
5856
self.native.on('error', function(err) {
@@ -70,6 +68,10 @@ Client.prototype.connect = function(cb) {
7068
});
7169
});
7270

71+
//signal we are connected now
72+
self.emit('connect');
73+
self._pulseQueryQueue(true);
74+
7375
//possibly call the optional callback
7476
if(cb) cb();
7577
});

0 commit comments

Comments
 (0)