Example bug and production site.#638
Conversation
|
Nice. But it makes me wonder why it is needed. I think a better solution is to make node-postgres prevent the insertion of such invalid, errored client, to the pool, making the call to done() not needed. I did not look at the source writing this, so it might not be possible in the design. |
|
You have a point there. I have not looked at the code either, which I should have actually done to start with. In any case, I found myself running out of clients due to the |
|
Ooh quick 'n easy! I'll look into it. But the done requirement for error'd connections sounds like a nogo for me.
|
|
So I see this line: https://github.com/brianc/node-postgres/blob/master/lib/pool.js#L75 Now, if it does indeed leak if you don't call done(), it means it does not go there. A couple of lines lower, you see the definition of the done() function: you should pass the error, so that the client is destroyed instead of released. I think this error is for connections that will fail to do anything else. If a simple query failed, the connection is still usable. So you should call done() if a connection error occurs. You can also see that it calls the callback you supplied there with error as null. So either you have an error in connect(), and it gives you an error and a NOOP done(), or you have an actual client and a usable done(). However, then error is null. pg.connect(function(err,client,done) {
// Either err contains an error, then err = Object, client = null, done = NOOP
if(err) {
// done(); // useless
throw 'Oh noes!'; // Fail, do not do any other stuff
}
// Or: err = null, client = Object, done = Function
// ....
client.on('error',function(e) {
console.log('Oh Noes!');
done(e); // I think this should solve it
});
done(); // releases client
});Is there anywhere in your code where you catch errors of the client (connection errors, client.on()), and call done(), but with no error supplied? If that is the case, you would, I think, run out of clients because no usable clients are in the pool. |
|
Well, I have to say, that makes much more sense. I went to look at the code and you are right. If calling the Thank you so far. |
The example code had a bug where the client was not being released back to the pull on error. Also added a production site using this module.