Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres): prevent crash if postgres connection emit multiple errors #15867

Merged
merged 11 commits into from
Apr 19, 2023

Conversation

Hackatosh
Copy link
Contributor

@Hackatosh Hackatosh commented Mar 28, 2023

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

We recently observed multiple crashes due to an unhandled "server conn crashed?" exception originating from the pg library. As best as I've been able to tell, this shouldn't be possible and should have been fixed in this previous PR : #14731

I think that an error might be able to slip up during the connection without the error listener being properly attached or that error can be fired multiple times and is only handled once.
My fix is to attach the listener before trying to connect to the database. Also I change back the .once handler to a .on (this was changed in the PR 14731) to be able to catch multiple errors.

Todos

@Hackatosh
Copy link
Contributor Author

PR for version 6 : #15868

@Hackatosh Hackatosh changed the title fix(postgres): prevent crash if postgres connection fails during conn… fix(postgres): prevent crash if postgres connection emit multiple errors Apr 3, 2023
@evanrittenhouse
Copy link
Member

LGTM - will wait for @ephys or @WikiRik to confirm, since they may have additional insight into to the Postgres error emission logic

evanrittenhouse
evanrittenhouse previously approved these changes Apr 6, 2023
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to make the casing of the type a bit nicer

packages/core/src/dialects/postgres/connection-manager.ts Outdated Show resolved Hide resolved
packages/core/src/dialects/postgres/connection-manager.ts Outdated Show resolved Hide resolved
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
@Hackatosh
Copy link
Contributor Author

Thanks for your input @WikiRik, I have updated the PR

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but I'll give @ephys some time to look at the typing change before I merge

@Hackatosh
Copy link
Contributor Author

Hello ! Any news on this PR ? @WikiRik @ephys

@WikiRik WikiRik merged commit 42fbcc4 into sequelize:main Apr 19, 2023
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants