Remove query emit 'end' event when query has error

Closes #547
This commit is contained in:
Brian M. Carlson 2014-04-06 11:53:47 -05:00
parent c3f5c06c44
commit 357b64d704
2 changed files with 9 additions and 5 deletions

View File

@ -93,11 +93,9 @@ Query.prototype.handleError = function(err, connection) {
//if callback supplied do not emit error event as uncaught error
//events will bubble up to node process
if(this.callback) {
this.callback(err);
} else {
this.emit('error', err);
return this.callback(err);
}
this.emit('end');
this.emit('error', err);
};
Query.prototype.submit = function(connection) {

View File

@ -12,10 +12,16 @@ test('error during query execution', function() {
pidColName = 'pid';
queryColName = 'query';
}
client.query(sleepQuery, assert.calls(function(err, result) {
var query1 = client.query(sleepQuery, assert.calls(function(err, result) {
assert(err);
client.end();
}));
//ensure query1 does not emit an 'end' event
//because it was killed and received an error
//https://github.com/brianc/node-postgres/issues/547
query1.on('end', function() {
assert.fail('Client with an error should not emit "end" event')
})
var client2 = new Client(helper.args);
client2.connect(assert.success(function() {
var killIdleQuery = "SELECT " + pidColName + ", (SELECT pg_terminate_backend(" + pidColName + ")) AS killed FROM pg_stat_activity WHERE " + queryColName + " = $1";