pool.on('error', handlerFunc) not handling all emitted errors
See original GitHub issueHi,
I’m seeing a behaviour where a pool with an error handler is picking up the emitted error only once. The subsequent emitted errors bubble up and become unhandled exceptions.
This happens when I call ‘pool.query’ multiple times in a load test and kill the connection to Postgres while the test is running. I’m using version 7.15.0. I am testing the application capacity of recovering after a db failure.
Sample code where I create the pool and add the listener.
newPool = new pg.Pool Object.assign {}, poolConfig
newPool.on 'error', (err) => console.error "[DBClient] Error in pool client.", err.stack
Then I simply call newPool.query
every time I get a hit on the API from the load test app.
In the output below, you can see that the error listener captures and prints the error, but right after that it doesn’t. The second output is from the top-level unhandled exceptions listener. All subsequent outputs are similar to the second one.
Output:
[DBClient] Error in pool client. Error: Connection terminated unexpectedly
at Connection.<anonymous> (/Users/myuser/app/lib/app-common/oprecord/coffee/node_modules/pg/lib/client.js:252:9)
at Object.onceWrapper (events.js:298:28)
at Connection.emit (events.js:209:13)
at Socket.<anonymous> (/Users/myuser/app/lib/app-common/oprecord/coffee/node_modules/pg/lib/connection.js:133:10)
at Socket.emit (events.js:214:15)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Unhandled Exception: Error: Connection terminated unexpectedly
at Connection.<anonymous> (/Users/myuser/app/lib/app-common/oprecord/coffee/node_modules/pg/lib/client.js:252:9)
at Object.onceWrapper (events.js:298:28)
at Connection.emit (events.js:209:13)
at Socket.<anonymous> (/Users/myuser/app/lib/app-common/oprecord/coffee/node_modules/pg/lib/connection.js:133:10)
at Socket.emit (events.js:214:15)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
How is it possible that in one line, the error is handled by the listener, and afterwards it’s not?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
ah dang - I’ll semver patch bump pg-pool & release it…then it should be available to be installed here. Sorry I missed that.
alrighty published
pg-pool@2.0.8
. I’m migrating it back into this repo here & will have better coordinated released w/ lerna so this kinda stuff wont get dropped as often soon. My plan is to have this done by the new year, pending any serious fires.