Skip to content

Commit 832e48a

Browse files
committed
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.
1 parent 0fcf709 commit 832e48a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var helper = require(__dirname + "/../test-helper");
2+
var pg = require(__dirname + "/../../../lib");
3+
helper.pg = pg;
4+
5+
helper.pg.defaults.poolSize = 1;
6+
7+
test('aborted transaction returned to pool', function() {
8+
helper.pg.connect(helper.config, assert.success(function(client) {
9+
client.id = 1;
10+
client.pauseDrain();
11+
client.query('begin;', assert.success(function() {
12+
// client.query('rollback;'); // <-- This causes the test to pass.
13+
client.query('select * from thistableshouldneverexist', function(err) {
14+
assert.ok(err);
15+
client.resumeDrain();
16+
helper.pg.connect(helper.config, assert.success(function(client) {
17+
assert.equal(client.id, 1);
18+
client.query("select * from person", assert.success(function(result) {
19+
console.log('Ending', result);
20+
helper.pg.end();
21+
}));
22+
}));
23+
});
24+
}));
25+
}));
26+
});

0 commit comments

Comments
 (0)