mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
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:
parent
7d534c235a
commit
6f8292435d
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
8
test/integration/gh-issues/882-tests.js
Normal file
8
test/integration/gh-issues/882-tests.js
Normal 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();
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user