"Called end on pool more than once"

See original GitHub issue

I’m getting an error “Called end on pool more than once” when I run close() on the pool when shutting down the application. I am doing it from the unhandledRejection handler to cleanly shut down in case of an unhandled rejection. But since this can be called more than once, close() is getting called more than once.

Is there any reason why this should cause an error? Can’t it just silently fail if called more than once? Isn’t calling it from a callback like unhandledRejection, which can get called many times, a standard use case?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

2reactions
joelmukuthucommented, Mar 25, 2019

Well, I wouldn’t consider it a feature that pool.end can be called more than once. If we assume pool.end to be closing connections, it doesn’t make sense that it can be called more than once, since that’s not how connections work in general. IMO it’s doing exactly the right thing, throwing an error if it’s called multiple times, and that the inverse would be a bug.

If there are cases that cause it to be called more than once on your application, then it makes more sense to handle that there. If anything, your code will serve as documentation for why pool.end is called multiple times.

1reaction
rightawaycommented, Mar 25, 2019

I see, then I guess my earlier question remains:

Maybe I’m not understanding what you meant, but if this endedPool check were handled by the pool itself then the callback could simply be this which is a lot clearer. What would be lost by moving this check into the pool? Since subsequent calls to pool.end() should always be a no op then wouldn’t it be better to let the pool take care of all this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Called end on pool more than once at BoundPool.end
Where did you find an example of calling .finally(db.$pool.end); at the end of an API call? You are destroying the connection pool after...
Read more >
node-postgres: struggling with this error - Reddit
Ever since I polluted my app with db.connect(async function(err, client, done)) in every middleware, my app hangs as I am navigating through ...
Read more >
Pooling – node-postgres
To shut down a pool call pool.end() on the pool. This will wait for all checked-out clients to be returned and then shut...
Read more >
pg.Pool.end JavaScript and Node.js code examples - Tabnine
release() { return this.pool.end(); ... Learn More. adv-img ... pgDb.end()) .then(async () => pgHandler.disconnect()) .then(async () => console.log('done')).
Read more >
Connection pools - psycopg 3.1.8.dev1 documentation
Failing to call close() at the end of the program is not terribly bad: probably ... If more connections than the ones available...
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