Clear Azure subscription/auth cache on manual registries refresh#548
Clear Azure subscription/auth cache on manual registries refresh#548bwateratmsft with Copilot wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR ensures the Azure registries view reflects Azure account/subscription changes without requiring a VS Code window reload by invalidating Azure auth/subscription caches on user-initiated manual refresh of the Registries view.
Changes:
- Added a
clearCache()mechanism inAzureRegistryDataProviderto clear cachedACROAuthProviderinstances and bypass the subscription cache on the next root load. - Updated
RefreshManagerto invokeclearCache()only for manual refreshes of the registries target.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| extensions/vscode-containers/src/tree/registries/Azure/AzureRegistryDataProvider.ts | Adds cache invalidation plumbing and a one-shot noCache subscription load to reflect sign-in/subscription changes. |
| extensions/vscode-containers/src/tree/RefreshManager.ts | Triggers Azure registries cache invalidation only on manual registries refresh. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * subscriptions or signed-in accounts are reflected without needing to reload the window. | ||
| */ | ||
| public clearCache(): void { | ||
| this.authenticationProviders.clear(); |
There was a problem hiding this comment.
Without having looked, is clearing the auth providers necessary or helpful?
There was a problem hiding this comment.
Yes, it is necessary. authenticationProviders is keyed by registry URL only, not by subscription or account. If the user changes accounts or subscriptions, getAuthenticationProvider() would return a cached ACROAuthProvider still bound to the old AzureSubscription and its (potentially stale/revoked) credential. That provider also holds a cached ACR refresh token (refreshTokenCache) derived from the old credential, which would be invalid after an account change. Without clearing the map, any subsequent registry operation (listing tags, deleting images, etc.) would fail with auth errors until the window was reloaded.
The Azure registries view cached subscriptions and auth providers indefinitely, so subscription or sign-in changes weren't reflected without reloading the window. Following the pattern in microsoft/vscode-azureresourcegroups#1292, cache invalidation is now triggered by a user-initiated manual refresh.
Changes
AzureRegistryDataProvider: addedclearCache(), which drops cachedACROAuthProviderinstances and flags the next root load to bypass the subscription cache viagetAvailableSubscriptions({ noCache }). The flag is consumed (reset) on that load.RefreshManager: callsclearCache()only on manual registries refresh (reason === 'manual' && target === 'registries'), leaving programmatic/debounced refreshes untouched so routine operations don't incur extra token/subscription requests.Per the azureauth v6 contract,
noCache: truescopes to that single call and is the intended mechanism when an account's accessible subscriptions/tenants may have changed.