GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Catch errors client throws in pool by zlotnika · Pull Request #2569 · brianc/node-postgres

Conversation

@zlotnika

@zlotnika zlotnika commented Jul 3, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Old behavior: if you do something like

try {
  await (new Pool()).query(null);
} catch (error) {
  console.log(error);
}

you get an uncaught exception. If you have a server that generates text to pass in to query the pool, it will crash your server.

New behavior: This change catches the error thrown at https://github.com/zlotnika/node-postgres/blob/master/packages/pg/lib/client.js#L505 and treats it the same as it does with any other. This way, a query of null works similarly to a query of 'over 9000' or new Date() or whatever other not-so-SQL-y thing you come up with.

An alternate solution would be to call the callback with an error in the client instead of throwing an error. I personally prefer throw-catching.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bryanph, pa3, a-xmd, robinbijlani, and ColinKinloch reacted with thumbs up emoji
All reactions
  • 👍 5 reactions
@bryanph

bryanph commented Oct 21, 2021

Copy link
Copy Markdown

I found the same is true for when failing to connect to the server, there's no way to catch the error. It simply crashes the app. I suppose this would resolve that as well. Would be great to see this merged 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Oct 21, 2021

Copy link
Copy Markdown
Owner

I apprecaite the contribution here. You're right, throwing errors on a method that accepts a callback or returns a promise is not a nice pattern. I will be happy to merge this if you write test coverage for the behavior. No tests, no merge for the most part as w/o tests its impossible for me to maintain backwards compatibility and prevent regressions long term. If you don't have time to write a test, I understand. In that case I'll try to come back & write test(s) for this & get it merged as soon as I can!

zlotnika and pa3 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zlotnika
zlotnika force-pushed the master branch from 4fab71e to c02b79e Compare October 21, 2021 17:41
@benk79

benk79 commented Jan 24, 2022

Copy link
Copy Markdown

IMHO this is a crucial point for an application to run in production. Error management is really a must, not just a nice to have. Tryed to see if i can write a test, but had so many already existing tests failing that gave up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benk79

benk79 commented Jan 24, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

My exact problem being almost the same as @bryanph but also for DB server being shut down or having failures, i finally ended with this simple solution

pool.on('connect', client => {
    client.on('error', (err)=> {
        pool.emit('error', err, client);
    });
});

Then handle the error from pool.on('error', fn);

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zlotnika
Catch errors client throws in pool
659fc32
@zlotnika
zlotnika force-pushed the master branch from c02b79e to 659fc32 Compare January 24, 2022 19:41
@zlotnika

zlotnika commented Jan 24, 2022

Copy link
Copy Markdown
Contributor Author

I've tried writing a test, but I can't seem to get testing working on my machine. It looks like there's a lot of stuff set up for this, but no clear documentation. Could anyone either 1. write a test for me or 2. add something on running tests to the Readme or 3. tell me where else to find info on it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zlotnika
Add a test
c60a8ac
This test _should be_ right
@zlotnika

zlotnika commented Jan 27, 2022

Copy link
Copy Markdown
Contributor Author

Alright. I've added a test that should work right. My environment is a bit different, so hopefully it'll run correctly on travis etc. Let me know if it works or whatever. Feel free to suggest fixes for it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@josh-cain

josh-cain commented May 23, 2022

Copy link
Copy Markdown

@brianc Is this PR still being considered? Have a problem similar to #2439 and was hoping to get something here in the upstream rather than fix elsewhere.

LeslieCarr reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bbeesley

bbeesley commented Aug 21, 2022

Copy link
Copy Markdown

Hey @brianc is there any chance of some feedback on this PR? We've been suffering this issue using node-postgres with big aws aurora clusters where I work. We keep getting paged about it since we're getting containers dying in production every 15 mins or so. Is there any reason not to merge this PR? If you need better test coverage then I'm happy to help @zlotnika out there. Just hoping to be able to avoid having to fork this repo and publish a patched version of it since it's overhead I'd much rather do without.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Aug 22, 2022

Copy link
Copy Markdown
Owner

yes i am sorry - you're absolutely right this should be merged, and I will do that now & get a new release out tomorrow. There's some epic storm in Austin right now so...my power is going in and out but i'll get ya patched up tomorrow along w/ a salvo of other fixes. Sorry for the delay!

zlotnika reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
brianc merged commit 8032fba into brianc:master Aug 22, 2022
brianc added a commit that referenced this pull request Aug 22, 2022
@brianc
Fix error handling test
8bd43a5
#2569 introduced a bug in the test. The test never passed but because travis-ci lovingly broke the integration we had a long time ago the tests weren't run in CI until I merged.  So, this fixes the tests & does a better job cleaning up the query in an errored state.
@brianc brianc mentioned this pull request Aug 22, 2022
Fix error handling test #2789
Merged
brianc added a commit that referenced this pull request Aug 23, 2022
@brianc
Fix error handling test (#2789)
a4ef6ce
* Fix error handling test

#2569 introduced a bug in the test. The test never passed but because travis-ci lovingly broke the integration we had a long time ago the tests weren't run in CI until I merged.  So, this fixes the tests & does a better job cleaning up the query in an errored state.

* Update sponsors
@shleeable shleeable mentioned this pull request Feb 23, 2023
[Dependashlee] Bump pg from 8.5.0 to 8.11.0 (JS) mastodon/mastodon#23815
Closed
@xvello xvello mentioned this pull request Jun 8, 2023
Catch errors thrown by connect #3004
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@zlotnika @bryanph @brianc @benk79 @josh-cain @bbeesley
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.