Client error: Connection terminated unexpectedly when server stops in the middle of running queries
See original GitHub issueHello,
I’m using a connection pool. My program gets a client from the pool and releases it after the query.
const client = await this.getClient();
await client.query(statement);
client.release();
I’m listening to all pool and client events. When my server stops the clients start to emit the following error event:
Connection terminated unexpectedly
at Connection.<anonymous> (/project/node_modules/pg/lib/client.js:272:71)
at Object.onceWrapper (events.js:420:28)
at Connection.emit (events.js:314:20)
at Socket.<anonymous> (/project/node_modules/pg/lib/connection.js:102:10)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1226:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
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 use pool.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)
after client.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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Client error: Connection terminated unexpectedly when server ...
Hello,. I'm using a connection pool. My program gets a client from the pool and releases it after the query. const client =...
Read more >node-postgres, Connection terminated unexpectedly
I have tried this, problem is asynchronous property of JavaScript. Connection is being ended before execution of query.
Read more >Understanding Heroku Postgres Log Statements and ...
This error can happen as a result of one of several intermittent network connectivity issues. If you are seeing this only intermittently, ...
Read more >Troubleshoot connecting to your instance - AWS Documentation
Check your instance to make sure it is running and has passed its status checks. ... Error: Server unexpectedly closed network connection.
Read more >Common Errors and Solutions | CockroachDB Docs
This message indicates a client is trying to connect to a node that is either not running or is not listening on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You still need the listener on the pool as well. Wherever you’re creating the pool,
Also,
off
needs to be used with the original function passed toon
, not just one with the same effect.please check: https://github.com/brianc/node-postgres/issues/2439#issuecomment-757691278