From 832e48a824956e55dd02876c7e4fab10747e045c Mon Sep 17 00:00:00 2001 From: Andrew DePue Date: Mon, 23 Jul 2012 12:36:54 -0500 Subject: [PATCH 1/2] Added test to reproduce problem with returning client to pool in a bad state If you start a transaction in a client and fail to roll that transaction back before calling resumeDrain, then an unsuspecting user will get an error the next time that client is pulled from the pool and a query executed against it. --- .../connection-pool/error-recover-tests.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/integration/connection-pool/error-recover-tests.js diff --git a/test/integration/connection-pool/error-recover-tests.js b/test/integration/connection-pool/error-recover-tests.js new file mode 100644 index 000000000..a7e90cfe0 --- /dev/null +++ b/test/integration/connection-pool/error-recover-tests.js @@ -0,0 +1,26 @@ +var helper = require(__dirname + "/../test-helper"); +var pg = require(__dirname + "/../../../lib"); +helper.pg = pg; + +helper.pg.defaults.poolSize = 1; + +test('aborted transaction returned to pool', function() { + helper.pg.connect(helper.config, assert.success(function(client) { + client.id = 1; + client.pauseDrain(); + client.query('begin;', assert.success(function() { + // client.query('rollback;'); // <-- This causes the test to pass. + client.query('select * from thistableshouldneverexist', function(err) { + assert.ok(err); + client.resumeDrain(); + helper.pg.connect(helper.config, assert.success(function(client) { + assert.equal(client.id, 1); + client.query("select * from person", assert.success(function(result) { + console.log('Ending', result); + helper.pg.end(); + })); + })); + }); + })); + })); +}); \ No newline at end of file From 8bf0229d059bf5ec2f8741d5f506e9e74379cc8a Mon Sep 17 00:00:00 2001 From: Andrew DePue Date: Mon, 23 Jul 2012 13:19:40 -0500 Subject: [PATCH 2/2] o Fixed location of 'commit' comment. --- test/integration/connection-pool/error-recover-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/connection-pool/error-recover-tests.js b/test/integration/connection-pool/error-recover-tests.js index a7e90cfe0..8f5910b26 100644 --- a/test/integration/connection-pool/error-recover-tests.js +++ b/test/integration/connection-pool/error-recover-tests.js @@ -9,9 +9,9 @@ test('aborted transaction returned to pool', function() { client.id = 1; client.pauseDrain(); client.query('begin;', assert.success(function() { - // client.query('rollback;'); // <-- This causes the test to pass. client.query('select * from thistableshouldneverexist', function(err) { assert.ok(err); + // client.query('rollback;'); // <-- This causes the test to pass. client.resumeDrain(); helper.pg.connect(helper.config, assert.success(function(client) { assert.equal(client.id, 1);