question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pool.on('error', handlerFunc) not handling all emitted errors

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brianccommented, Dec 19, 2019

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

1reaction
brianccommented, Dec 19, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I improve error handling on a pool - node.js
const pool = require('../config/config.js'); class User { constructor(user) { this.username = user.username; this.email = user.email; ...
Read more >
Handling Exceptions - Apple Developer
Explains how to raise and handle exceptions in Cocoa applications.
Read more >
Node.js v19.3.0 Documentation
All errors thrown by the node:assert module will be instances of the AssertionError class. ... In both cases the error handler is skipped....
Read more >
Error Handling In Rust - A Deep Dive - A learning journal
Control flow is scripted: all information required to take a decision on what to do next must be accessible to a machine. We...
Read more >
pg.Pool.on JavaScript and Node.js code examples - Tabnine
No need for a server, let's just spin up the schema builder (async (): Promise<void> => { const pgPool = new Pool(pgConfig); pgPool.on('error', ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found