prevent exceptions in callback from locking up the postgres client - #332
prevent exceptions in callback from locking up the postgres client#332twobitfool wants to merge 1 commit into
Conversation
|
When the query emits 'end' the client which owns the query checks it's internal queue of queries to see about issuing another one. If the client has no more queries it will emit a 'drain'. This would have been a much more difficult problem in the past with the weird var client = new Client('blalba');
//automatically close the client when its empty
client.on('drain', client.end.bind(client));
client.query('SELECT * FROM whatever', function() {
//client has at this point emitted drain and is in the process of closing
//so this next query will error out
client.query('SELECT * FROM something_else', function() {
});
});I'm not saying the above code example is good code, but I'm using it to demonstrate moving the callback into
|
|
I kind of like the "dirty" try/catch idea. It's direct, and it may perform better than putting the callback and |
|
fixed in pg@1.0.2 Thanks for your code - normally I accept & don't reimplement but there were some tweaks I wanted to put in. |
When the code in the callback raises an exception (e.g. an assert in test code) the next query will never fire. This prevents that issue by firing the callback on nextTick.
Note: Tests lifted from https://github.com/NiKnight/node-postgres/commit/d4b99763bc7760bf9add414da2d38510596c69df on #282