Skip to content

Commit bf258e8

Browse files
author
Sandro Santilli
committed
Ensure connect callback is invoked on premature socket hangup
Closes brianc#534
1 parent 59f9c28 commit bf258e8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/client.js

+8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Client.prototype.connect = function(callback) {
167167
self.emit('error', error);
168168
} else {
169169
callback(error);
170+
callback = null;
170171
}
171172
} else {
172173
//need to sync after error during a prepared statement
@@ -180,6 +181,13 @@ Client.prototype.connect = function(callback) {
180181
});
181182

182183
con.once('end', function() {
184+
if ( callback ) {
185+
// haven't received a connection message yet !
186+
var err = new Error("Stream unexpectedly ended before getting ready for query execution");
187+
callback(err);
188+
callback = null;
189+
return;
190+
}
183191
if(self.activeQuery) {
184192
self.activeQuery.handleError(new Error('Stream unexpectedly ended during query execution'));
185193
self.activeQuery = null;

0 commit comments

Comments
 (0)