Conversation
There was a problem hiding this comment.
Pull request overview
Adds a centralized, shared Entra (Azure MFA) SQL access-token cache in ConnectionManager so multiple editors/tabs using the same Entra account+tenant can reuse refreshed tokens and reduce repeated re-auth prompts.
Changes:
- Introduces a shared Entra SQL token cache plus an “in-flight refresh” map to dedupe concurrent refreshes.
- Replaces
confirmEntraTokenValiditywithrefreshEntraTokenIfNeededand wires it into relevant connection flows. - Adds unit tests covering cache usage, refresh behavior, coalescing parallel refreshes, and cache clearing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| extensions/mssql/src/controllers/connectionManager.ts | Implements shared Entra SQL token caching and coalesced refresh logic; integrates cache clearing. |
| extensions/mssql/test/unit/connectionManager.test.ts | Adds unit tests validating cache reuse, refresh, parallel coalescing, and cache clearing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
PR Changes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21434 +/- ##
==========================================
+ Coverage 73.25% 73.35% +0.09%
==========================================
Files 328 328
Lines 99451 99588 +137
Branches 5649 5683 +34
==========================================
+ Hits 72851 73050 +199
+ Misses 26600 26538 -62
🚀 New features to boost your workflow:
|
| token.onCancellationRequested(() => { | ||
| reject({ | ||
| status: ApiStatus.Cancelled, | ||
| message: "Azure sign in cancelled by user.", | ||
| } as Status); | ||
| }); | ||
| try { | ||
| const refreshedToken = await refreshTask(); | ||
| resolve(refreshedToken); | ||
| } catch (error) { | ||
| const refreshErrorStatus: Status = { | ||
| status: ApiStatus.Error, | ||
| message: getErrorMessage(error), | ||
| }; | ||
| reject(refreshErrorStatus); | ||
| } |
There was a problem hiding this comment.
After cancellation triggers reject(...), the code can still proceed to refreshTask() and later call resolve(...)/reject(...) again (since the cancellation handler doesn’t short-circuit the async flow). This can lead to unnecessary interactive auth continuing even after the user cancels. Consider tracking a cancelled flag (set in the cancellation handler) and returning early before starting refreshTask(), and/or checking token.isCancellationRequested before and after the refresh call.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
…h logic (#21721) * Initial plan * Handle undefined return from refreshAccessToken and add unit test Co-authored-by: Benjin <1609827+Benjin@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/vscode-mssql/sessions/1f79676e-8ac6-4a8f-b67c-1decd029bfb3 * Remove withProgressStub check from undefined token test Co-authored-by: Benjin <1609827+Benjin@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/vscode-mssql/sessions/dc0023a0-9d00-490e-bbc8-489393c6427f --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Benjin <1609827+Benjin@users.noreply.github.com>
Description
Further improvements upon #20352
Originally, each connection instance had its own copy of the token spawned/copied from the Object Explorer node, so when that token expired and was refreshed, that refreshed token would live only within its owner.
#20352 improved this by updating the OE token copy when an editor spawned from it needed to reconnect, ensuring that future new editors get the updated token.
This change takes that a step further by sharing a token cache across all connections with the following behavior:
This way, when the user has multiple tabs open for the same connection, updated tokens are picked up from the cache to minimize the number of times a user is prompted for re-authentication.
Code Changes Checklist
npm run test)Reviewers: Please read our reviewer guidelines