- Notifications
You must be signed in to change notification settings - Fork3
feat: fetch hostname suffix from API#103
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
spikecurtis commentedMay 15, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This stack of pull requests is managed byGraphite. Learn more aboutstacking. |
private string _domainSuffix = DefaultSuffix; | ||
private bool _dirty = false; | ||
private bool _getInProgress = false; | ||
private CredentialModel _credentialModel = new() { State = CredentialState.Invalid }; |
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.
We should just fetch this on-demand from the CredentialManager (since it's cheap) rather than storing it 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.
I tried this, but it complicates things considerably in terms of race conditions because you can't synchronize changes toGetCachedCredentials
with the other items we track here like_dirty
, so its hard to guarantee the correct behavior. Writing updates to this while holding the lock ends up being much simpler.
using var _ = _lock.Lock(); | ||
_logger.LogDebug("credentials updated with state {state}", credentials.State); | ||
_credentialModel = credentials; | ||
if (credentials.State != CredentialState.Valid) return; |
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.
Should you set the stored domain back to the default in this case?
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.
Maybe it would be better to just always create the task if the credentials changed (i.e. remove this check here) and do the check once in the task.
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.
I don't think we should set the stored domain back to the default. The most common scenario for getting invalid creds is probably a logout or expired token --- so it's not particularly likely that the Default is more correct.
In any case, once we sign back in we'll get the correct value.
In terms of avoiding the check and always creating the task, seems like a lot of churn (locking, creating tasks, dropping logs) to avoid one conditional.
Uh oh!
There was an error while loading.Please reload this page.
} | ||
using var l = await _lock.LockAsync(CancellationToken.None); | ||
if ((_dirty || prev.IsFaulted) && _credentialModel.State == CredentialState.Valid) |
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.
_dirty
seems to only be true here if the credentials became invalid between when the event was handled and the task started. So the only way for this to trigger would be if credentials became valid, then became invalid, then became valid again, which seems very unlikely to actually happen. The user would need to sign in or start the app, then sign out, then enter their credentials and sign back in (with API auth check latency included).
You could probably also accomplish the same thing without needing a bool by throwing in the credential state guard at the top ofRefresh()
, and only relying onprev.IsFaulted
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.
The idea of_dirty
is that while we are making the network call a new, valid credential for a different deployment could come in. That is, just because we had a valid credential when we started our work, and have a valid credential at the end, it doesn't mean thatit was the same credential. If that happens then we refresh to ensure we have the correct value from the new credential.
} | ||
} | ||
private async Task Refresh() |
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 should probably just take the credentials model as an argument.
spikecurtisMay 16, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
We want to clear the_dirty
flag while grabbing the most up to date credential (holding the lock), then any later valid credentials that come in will re-set the_dirty
flag. That doesn't work if we pass the credential as an argument because we can't guarantee it's the "latest" if we're not holding the lock.
3afa871
to427a8f6
Comparebe72f80
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fixes#49
Adds support to query the hostname suffix from Coder server, and then propagates any changes to the agent view models.