From d14700e7e52ede72b5ec9244de5e26f55cf1eaf0 Mon Sep 17 00:00:00 2001 From: John Shepard Date: Wed, 2 Mar 2016 21:26:02 -0800 Subject: [PATCH 1/2] add check before accessing activeQuery --- lib/client.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/client.js b/lib/client.js index f0a374d32..8b388063b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -100,44 +100,58 @@ Client.prototype.connect = function(callback) { //delegate rowDescription to active query con.on('rowDescription', function(msg) { - self.activeQuery.handleRowDescription(msg); + if (self.activeQuery) { + self.activeQuery.handleRowDescription(msg); + } }); //delegate dataRow to active query con.on('dataRow', function(msg) { - self.activeQuery.handleDataRow(msg); + if (self.activeQuery) { + self.activeQuery.handleDataRow(msg); + } }); //delegate portalSuspended to active query con.on('portalSuspended', function(msg) { - self.activeQuery.handlePortalSuspended(con); + if (self.activeQuery) { + self.activeQuery.handlePortalSuspended(con); + } }); //deletagate emptyQuery to active query con.on('emptyQuery', function(msg) { - self.activeQuery.handleEmptyQuery(con); + if (self.activeQuery) { + self.activeQuery.handleEmptyQuery(con); + } }); //delegate commandComplete to active query con.on('commandComplete', function(msg) { - self.activeQuery.handleCommandComplete(msg, con); + if (self.activeQuery) { + self.activeQuery.handleCommandComplete(msg, con); + } }); //if a prepared statement has a name and properly parses //we track that its already been executed so we don't parse //it again on the same client con.on('parseComplete', function(msg) { - if(self.activeQuery.name) { + if(self.activeQuery && self.activeQuery.name) { con.parsedStatements[self.activeQuery.name] = true; } }); con.on('copyInResponse', function(msg) { - self.activeQuery.handleCopyInResponse(self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyInResponse(self.connection); + } }); con.on('copyData', function (msg) { - self.activeQuery.handleCopyData(msg, self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyData(msg, self.connection); + } }); con.on('notification', function(msg) { From e8f4afba73d44049cc4de180fc6ac0e00c7a4f35 Mon Sep 17 00:00:00 2001 From: John Shepard Date: Wed, 2 Mar 2016 21:26:02 -0800 Subject: [PATCH 2/2] add check before accessing activeQuery --- lib/client.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/client.js b/lib/client.js index f0a374d32..8b388063b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -100,44 +100,58 @@ Client.prototype.connect = function(callback) { //delegate rowDescription to active query con.on('rowDescription', function(msg) { - self.activeQuery.handleRowDescription(msg); + if (self.activeQuery) { + self.activeQuery.handleRowDescription(msg); + } }); //delegate dataRow to active query con.on('dataRow', function(msg) { - self.activeQuery.handleDataRow(msg); + if (self.activeQuery) { + self.activeQuery.handleDataRow(msg); + } }); //delegate portalSuspended to active query con.on('portalSuspended', function(msg) { - self.activeQuery.handlePortalSuspended(con); + if (self.activeQuery) { + self.activeQuery.handlePortalSuspended(con); + } }); //deletagate emptyQuery to active query con.on('emptyQuery', function(msg) { - self.activeQuery.handleEmptyQuery(con); + if (self.activeQuery) { + self.activeQuery.handleEmptyQuery(con); + } }); //delegate commandComplete to active query con.on('commandComplete', function(msg) { - self.activeQuery.handleCommandComplete(msg, con); + if (self.activeQuery) { + self.activeQuery.handleCommandComplete(msg, con); + } }); //if a prepared statement has a name and properly parses //we track that its already been executed so we don't parse //it again on the same client con.on('parseComplete', function(msg) { - if(self.activeQuery.name) { + if(self.activeQuery && self.activeQuery.name) { con.parsedStatements[self.activeQuery.name] = true; } }); con.on('copyInResponse', function(msg) { - self.activeQuery.handleCopyInResponse(self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyInResponse(self.connection); + } }); con.on('copyData', function (msg) { - self.activeQuery.handleCopyData(msg, self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyData(msg, self.connection); + } }); con.on('notification', function(msg) {