Open
Description
I've setup my application's pool with an on('error')
hook to log errors that happen outside queries.
However, this hook is not always active between queries. If I acquire a connection from the pool to run a transaction, and that transaction falls afoul of the idle_in_transaction_session_timeout
, the error thrown from there doesn't happen during a query, and so if I don't take extra steps to add an on('error')
listener for each such connection, my app dies.
But I also have to make sure to manually remove those, since releasing the client back to the pool doesn't do so!
Is there a recommended way to do this "nicely"?
I see some possible ways to make this more ergonomic, which might be applied in combination:
- Apply that idle error listener from the pool even when the client is acquired
- This probably would need to be combined with some logic to avoid calling it if a "per-acquire" error listener is attached
- Automatically clear client error listeners on release to the pool
- e.g. call
client.removeAllListeners('error')
just before re-adding the idle listener here: https://github.com/brianc/node-postgres/blob/master/packages/pg-pool/index.js#L329 - This still leaves a race window between when the idle listener is removed acquiring a client connection and when the calling code can add its custom listener.
- This race may be avoidable when using the callback style, but it's pretty hard to avoid when using Promises.
- e.g. call
Metadata
Metadata
Assignees
Labels
No labels