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: silent refresh errors on active connection #219

Merged
merged 5 commits into from
Sep 26, 2023

Conversation

ruyadorno
Copy link
Contributor

@ruyadorno ruyadorno commented Sep 22, 2023

When an instance already have active connections, it should not throw errors when trying to refresh cloud instance certificates in the background. Otherwise these errors will bubble up and stop the end user application.

This PR fixes it by adding a more resilient system to the CloudSQLInstance refresh logic that silents errors occured during refresh and keeps valid certificate data that can be used if a refresh is still ongoing or if any error happens when during a refresh.

Fixes: #201

When an instance already have active connections, it should not throw
errors when trying to refresh cloud instance certificates in the
background. Otherwise these errors will bubble up and stop the end user
application.

This changeset fixes it by adding a more resilient system to the
CloudSQLInstance refresh logic that silents errors occured during
refresh and keeps valid certificate data that can be used if a refresh
is still ongoing or if any error happens when during a refresh.

Fixes: #201
@ruyadorno ruyadorno force-pushed the fix-silent-refresh-errors-on-active-connection branch from 90fadef to c9ec581 Compare September 22, 2023 21:58
src/cloud-sql-instance.ts Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
src/cloud-sql-instance.ts Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
@jackwotherspoon
Copy link
Collaborator

@ruyadorno Let's try and keep naming consistent across languages where we can. This will help the long-term maintenance burden and allow future maintainers to ramp up on the code base a lot quicker.

src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
test/cloud-sql-instance.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

I feel like we may be missing the equivalent of isValid in this PR?

Having an isValid function will give us a fix to #220 for free without any re-work.

src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
src/cloud-sql-instance.ts Outdated Show resolved Hide resolved
// refresh errors to the final user, scheduling a new refresh instead.
if (this.stablishedConnection) {
if (currentRefreshId === this.scheduledRefreshID) {
this.scheduleRefresh();
Copy link
Member

Choose a reason for hiding this comment

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

What happens to caller here? Do we block them until a new refresh is done? What happens if the refresh continues to fail? Do we block the event loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we never block the event loop. What happens is that the current metadata value is still used for connections in that case.

@ruyadorno ruyadorno force-pushed the fix-silent-refresh-errors-on-active-connection branch from 095ecc4 to 0447d6e Compare September 26, 2023 21:17
test/cloud-sql-instance.ts Outdated Show resolved Hide resolved
Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
@ruyadorno ruyadorno merged commit 41a8e79 into main Sep 26, 2023
29 checks passed
@ruyadorno ruyadorno deleted the fix-silent-refresh-errors-on-active-connection branch September 26, 2023 21:48
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.

Bad refresh should fail silently if metadata and cert are still valid
3 participants