-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Client error: Connection terminated unexpectedly when server stops in the middle of running queries #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Correct error handling when checking out a client is a bit cumbersome right now: const pool = new Pool();
pool.on('error', error => {
});
const clientErrorListener = error => {
};
const client = await pool.connect();
let clientError = null;
client.on('error', clientErrorListener);
try {
await client.query(statement);
} catch (err) {
clientError = err;
} finally {
client.release(clientError);
client.off('error', clientErrorListener);
} If you’re only making one query, though, the pool can do that for you. await pool.query(statement); |
Hello @charmander, First, thanks for your reply. I tried both methods but unfortunately, I'm still experiencing errors. First method:
Second method:
Both methods resulted on the same error:
|
You still need the listener on the pool as well. Wherever you’re creating the pool, pool.on('error', error => {
console.error('idle client error:', error);
}); Also, |
I refactored my code.
Also my pool is listening to the error event:
Unfortunately, I'm still getting the same results. |
Do you have a self-contained script that can reproduce this problem? I'd like to turn it into a unit test & fix it. |
A Larger problem for me is that unexpected disconnections seem to lead to full traceback including keys if you specify them for server SSL. |
that is an issue - i think we need to make that parameter non-enumerable. I can open a new issue on that one |
If you link to it, I'd be grateful to see the approach. There may be something I'm unaware of, but I am uncertain if it is node internals outputting or part of the library, where I guess an block-list or allow-list might be a reasonable thing to implement (or skipping config altogether) as you can then use something trivial (if it's application-side) such as |
I've just tested and out-of-library this can be mitigated using the following after defining an object instance databaseConfig Object.defineProperty(databaseConfig, 'password', {
enumerable: false
})
Object.defineProperty(databaseConfig.ssl, 'key', {
enumerable: false
}) This does not stop the connection, but does omit the private key and (if it was not already omitted) password if the server disconnects during running. |
please check: #2439 (comment) |
Hello,
I'm using a connection pool. My program gets a client from the pool and releases it after the query.
I'm listening to all pool and client events. When my server stops the clients start to emit the following error event:
The problem is, eventually I get an Unhandled 'error' event from clients. I already tried to use
client.release(true)
to destroy all the clients that emit an error event, tried to usepool.end()
after a client sends an error event but nothing seems to work.The only thing that works for me is calling
client.release(true)
afterclient.query(statement)
every time even when there is no error, but there is no point in using a pool if I'm always destroying connections.I'm using node-postgres 8.2.1.
Thanks in advance
The text was updated successfully, but these errors were encountered: