Node-postgres: pool.on('error', handlerFunc) not handling all emitted errors

Created on 18 Dec 2019  Â·  7Comments  Â·  Source: brianc/node-postgres

Hi,

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?

bug

Most helpful comment

ah dang - I'll semver patch bump pg-pool & release it...then it should be available to be installed here. Sorry I missed that.

All 7 comments

If there are queries running in parallel at that time, it could be the lack of this fix that just got merged: brianc/node-pg-pool#131

If there are queries running in parallel at that time, it could be the lack of this fix that just got merged: brianc/node-pg-pool#131

I see that change is merged. when will it be release in node-postgres?

@brianc @charmander I've manually imported the merged fix into my env and it did fix the issue. Any timeline to release this fix in 'pg' package? Then this bug here can be closed.

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 [email protected]. 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.

awesome, thanks for the quick reply @brianc ! happy holidays!

You too! :tada:

On Thu, Dec 19, 2019 at 8:19 AM Marcos TGS notifications@github.com wrote:

awesome, thanks for the quick reply @brianc https://github.com/brianc !
happy holidays!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/brianc/node-postgres/issues/2029?email_source=notifications&email_token=AAAMHIKSPAF5WM3BIIQAIQLQZN7G7A5CNFSM4J4NOVA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHJXYLI#issuecomment-567508013,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAMHIMX25P3NSSOOA6CO4TQZN7G7ANCNFSM4J4NOVAQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gpanainte picture gpanainte  Â·  3Comments

Cosrnos picture Cosrnos  Â·  3Comments

KeynesYouDigIt picture KeynesYouDigIt  Â·  3Comments

joaquimknox picture joaquimknox  Â·  3Comments

dindurthy picture dindurthy  Â·  4Comments