Respond to emptyQuery with a sync message

When a __prepared statement__ has no body in the query the backend responds with an `emptyQuery` message but never with a `commandComplete` or `errorResponse` message.  The client was hanging forever waiting for one of the other two expected messages.  The server was hanging forever waiting for the client to respond with a `sync` message.  This change has the client send the required `sync` on receipt of an `emptyQuery` message when the query is a prepared statement.  Fixes #822
This commit is contained in:
brianc 2015-08-01 18:45:50 -05:00
parent 7d534c235a
commit 6f8292435d
3 changed files with 22 additions and 0 deletions

View File

@ -113,6 +113,11 @@ Client.prototype.connect = function(callback) {
self.activeQuery.handlePortalSuspended(con);
});
//deletagate emptyQuery to active query
con.on('emptyQuery', function(msg) {
self.activeQuery.handleEmptyQuery(con);
});
//delegate commandComplete to active query
con.on('commandComplete', function(msg) {
self.activeQuery.handleCommandComplete(msg, con);

View File

@ -72,6 +72,15 @@ Query.prototype.handleCommandComplete = function(msg, con) {
}
};
//if a named prepared statement is created with empty query text
//the backend will send an emptyQuery message but *not* a command complete message
//execution on the connection will hang until the backend receives a sync message
Query.prototype.handleEmptyQuery = function(con) {
if (this.isPreparedStatement) {
con.sync();
}
};
Query.prototype.handleReadyForQuery = function() {
if(this._canceledDueToError) {
return this.handleError(this._canceledDueToError);

View File

@ -0,0 +1,8 @@
//client should not hang on an empty query
var helper = require('../test-helper');
var client = helper.client();
client.query({ name: 'foo1', text: null});
client.query({ name: 'foo2', text: ' ' });
client.query({ name: 'foo3', text: '' }, function(err, res) {
client.end();
});