From 75eb0948ad8f21e8cee45654a219641731c9cf3e Mon Sep 17 00:00:00 2001 From: jezell Date: Wed, 16 Jan 2013 17:33:03 -0800 Subject: [PATCH 1/3] Update lib/client.js Fix hang when connection drops after submitting query --- lib/client.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/client.js b/lib/client.js index 46f9eda19..a05bbb488 100644 --- a/lib/client.js +++ b/lib/client.js @@ -43,6 +43,13 @@ p.connect = function(callback) { } else { con.connect(this.port, this.host); } + + // if connection drops while query is being executed, forward an error to the query + con.stream.on('end', function() { + if(self.activeQuery) { + self.activeQuery.handleError(new Error('CONNECTION WAS DROPPED!')); + } + }); //once connection is established send startup message From 6329831f81768baad7b5387729161a3dd6e6ba73 Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Thu, 17 Jan 2013 09:59:56 -0800 Subject: [PATCH 2/3] Add support for unexpected connection termination --- lib/client.js | 17 +++++++++-------- lib/connection.js | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/client.js b/lib/client.js index a05bbb488..84053164b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -43,14 +43,6 @@ p.connect = function(callback) { } else { con.connect(this.port, this.host); } - - // if connection drops while query is being executed, forward an error to the query - con.stream.on('end', function() { - if(self.activeQuery) { - self.activeQuery.handleError(new Error('CONNECTION WAS DROPPED!')); - } - }); - //once connection is established send startup message con.on('connect', function() { @@ -141,6 +133,15 @@ p.connect = function(callback) { self._pulseQueryQueue(); }); + // if connection drops while query is being executed, forward an error to the query + con.on('end', function() { + self.emit('end'); + if(self.activeQuery) { + self.activeQuery.handleError(new Error('Connection was dropped while attempting to execute a query!')); + self.activeQuery = null; + } + }); + con.on('error', function(error) { if(!self.activeQuery) { if(!callback) { diff --git a/lib/connection.js b/lib/connection.js index ccc5571b7..570b908f7 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -37,6 +37,11 @@ p.connect = function(port, host) { this.stream.on('connect', function() { self.emit('connect'); }); + + // if connection drops while query is being executed, forward an error to the query + con.stream.on('end', function() { + self.emit('end'); + }); this.stream.on('error', function(error) { self.emit('error', error); From 0f3b4ff8efac5d7e175f8a5d429973b78695ca1d Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Thu, 17 Jan 2013 10:13:02 -0800 Subject: [PATCH 3/3] attach to stream end --- lib/connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connection.js b/lib/connection.js index 570b908f7..37ad47d5b 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -39,7 +39,7 @@ p.connect = function(port, host) { }); // if connection drops while query is being executed, forward an error to the query - con.stream.on('end', function() { + this.stream.on('end', function() { self.emit('end'); });