-
Notifications
You must be signed in to change notification settings - Fork 15
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
BCDA-3710 - Resolve issues with stale db connections #600
Conversation
This reverts commit e503d69.
] | ||
pruneopts = "UT" | ||
revision = "90697d60dd844d5ef6ff15135d0203f65d2f53b8" | ||
revision = "4604d39ddc9f62e2ca152114c73aec99b77a3468" | ||
version = "v1.9.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes issue related to invalid connections when using the pg driver.
# Since we've rebuilt the databases, we need to restart the worker and api | ||
# to ensure it picks up connections to the new db instance. | ||
# TODO (BCDA-3710) we should be able to remove this line once we have connection pooling on the worker | ||
# Ensure components are started as expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needed to keep this restart here because of issues uncovered in our CI process. It's caused by the database being dropped while the app is initializing.
Removing the TODO since the restart is not related to the restarting of the db instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM! Not super comfortable with go routines but this all makes sense to me.
There was a problem hiding this 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
// With que-go locked to pgx v3, we need a mechanism that will allow us to | ||
// discard bad connections in the pgxpool (see: https://github.com/jackc/pgx/issues/494) | ||
// This implementation is based off of the "fix" that is present in v4 | ||
// (see: https://github.com/jackc/pgx/blob/v4.10.0/pgxpool/pool.go#L333) | ||
// Use the same approach to validate the connection associated with the gorm client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to link to resources explaining the implementation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reapproving!
Fixes BCDA-3710
Previously, our driver dependencies (pg [v1.0.0] and pgx [v3.2.0]) had issues with re-using stale connections. For example, if our database instances were restarted, we would receive invalid/dead connection errors.
Issues:
We cannot upgrade our pgx driver to v4 because of an incompatibility with our que-go dependency. que-go relies on pgx v3 with no plans to move up to pgx v4.
The pg driver issue was resolved in this PR.
Change Details
No changes are needed to the pgx driver used in bcdaworker. Since we instantiate a quego worker, there's goroutine(s) that run that verify and refresh the connection pool. See.
Security Implications
new software dependencies
Upgraded our pg client from v1.0.0 to v1.9.0
security controls or supporting software altered
new data stored or transmitted
security checklist is completed for this change
requires more information or team discussion to evaluate security implications
no PHI/PII is affected by this change
Acceptance Validation
When running this, we would encounter failures because of the invalid connections: