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: support PG reconnects #9663

Merged
merged 1 commit into from
Apr 23, 2024
Merged

fix: support PG reconnects #9663

merged 1 commit into from
Apr 23, 2024

Conversation

mattkrick
Copy link
Member

@mattkrick mattkrick commented Apr 22, 2024

Description

fixes #9643

When the DB disconnects, it's nice to reconnect it.
This is a ridiculously hard problem as it turns out:
brianc/node-postgres#1324
brianc/node-postgres#2112

Depending on when & how the disconnect happens, the client may not be aware of it.

For example:

  • If PG sends terminating connection due to administrator command then the PG client reports the error Connection terminated unexpectedly and the app gets killed. I think it gets killed because it's a ProcessInterrupts routine coming from postgres.c and the severity is FATAL.
  • If PG sends the database system is shutting down then it reconnects just as expected. This is what we've seen coming from Google CloudSQL.
  • The driver also does not throw an error if a first connection hasn't happened, this is because the error event comes from a single connection, so if no connection is made, it can't emit that event, we just get econnrefused. I'm ignoring this case in this PR.

Demo

start up the embedder & then kill the PG container in docker. sometimes you get case 1, sometimes case 2.

Signed-off-by: Matt Krick <matt.krick@gmail.com>
@mattkrick mattkrick merged commit 32574a6 into master Apr 23, 2024
7 checks passed
@mattkrick mattkrick deleted the fix/pg-driver-error branch April 23, 2024 19:14
@github-actions github-actions bot mentioned this pull request Apr 25, 2024
24 tasks
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.

Embedder does not crash on error
1 participant