Skip to content

fix(postgres): prevent crash if postgres connection fails immediately (v6) - #14731

Merged
WikiRik merged 1 commit into
sequelize:v6from
schmod:postgres-error-handler
Jul 11, 2022
Merged

WikiRik merged 1 commit into
sequelize:v6from
schmod:postgres-error-handler

Conversation

@schmod

@schmod schmod commented Jul 8, 2022 •

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Please make sure to review and check all of these items:

  • Have you added new tests to prevent regressions?
  • Does yarn test or yarn test-DIALECT pass with this change (including linting)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • 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?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

We recently observed a crash due to an unhandled Connection terminated unexpectedly exception originating from the pg library. As best as I've been able to tell, this shouldn't be possible, and I've had difficulty reproducing it.

However, upon reading through the current implementation of the Postgres connection-manager, I noticed that we don't immediately attach an error-handler to the pg connection.

Based off of my reading of this code, it actually seems reasonably possible that an error emitted during either of the setup queries could trigger a hard crash. Moving the error-handler to an earlier phase of the connection's lifecycle should, in theory, make this a bit safer, and guard against any errors that are emitted very early in the connection's lifecycle.

Given the difficulty associated with reproducing this issue, I haven't been able to write an automated test-case to reproduce the issue or validate the fix. However, I'm reasonably confident that this fix is safe, and unlikely to make anything worse.

Todos

  • Add an automated test (if possible)

@schmod
schmod changed the base branch from main to v6 July 8, 2022 19:05
@schmod schmod changed the title Postgres error handler fix(postgres): prevent crash if postgres connection fails immediately after connection (v6) Jul 8, 2022
@schmod schmod changed the title fix(postgres): prevent crash if postgres connection fails immediately after connection (v6) fix(postgres): prevent crash if postgres connection fails immediately (v6) Jul 8, 2022

@ephys ephys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a good change. Thank you for the PR!
I don't see how we would go about writing a test to prevent a regression either unfortunately

I see this is targeting v6. In order to avoid losing this PR in v7, could you also make a PR that targets main?

@schmod

schmod commented Jul 11, 2022 •

Copy link
Copy Markdown
Contributor Author

v7/main PR: #14731 (Apologies if I did this in the wrong order!)

@WikiRik
WikiRik merged commit 90bb694 into sequelize:v6 Jul 11, 2022
@WikiRik

WikiRik commented Jul 11, 2022

Copy link
Copy Markdown
Member

Thanks for the two PRs!

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.21.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants