Skip to content

Fix MSAL initialization - #69726

Merged
Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/msal-init
Oct 16, 2026
Merged

Youssef1313 merged 1 commit into
mainfrom
dev/ygerges/msal-init

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

We regressed MSAL initialization in #66055.

In that PR, we added await AuthenticationService.instance.initialize(); before initializeMsalHandler call.

That means, two calls to init could overlap in a way that's not safe.

  • Call A: AuthenticationService._initialized is false, we enter the if.
  • Call A: Create MsalAuthorizeService and assign to instance.
  • Call A: Calls await initialize(), subsequent lines are waiting for this promise to complete.
  • Call B: AuthenticationService._initialized is false, we enter the if.
  • Call B: Create yet another MsalAuthorizeService and assign to instance (the same static field).
  • Call B: Calls await initialize() (on the second instance).
  • Call A: the first initialize promise completes, and we call AuthenticationService.instance.initializeMsalHandler, but now that is the second instance that's not yet initialized.

Fixes (hopefully) #68549 - intentionally not closing that issue until we are confident about the fix and backport it to 10.0.x.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:16
@Youssef1313
Youssef1313 requested a review from a team as a code owner October 8, 2026 12:16
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Required frozen review evidence was unavailable, leaving implementation and regression coverage insufficiently validated for approval.

0 open findings

What changed in this PR

Addresses the reported MSAL initialization race affecting Blazor WebAssembly authentication after refresh.

Changes:

  • Shares one initialization promise across concurrent callers and allows retries after failure.
  • Adds unit coverage for sequential, overlapping, and failed initialization.
  • Adds browser coverage for concurrent initialization and page refresh.
File Description
src/​Components/​WebAssembly/​Authentication.Msal/​test/​AuthenticationService.test.ts Tests initialization ordering, reuse, and retries.
src/​Components/​WebAssembly/​Authentication.Msal/​src/​Interop/​AuthenticationService.ts Shares initialization and retains the matching client.
src/​Components/​Web.JS/​jest.config.js Includes the MSAL unit tests.
src/​Components/​test/​testassets/​Components.WasmRemoteAuthentication/​Components.WasmRemoteAuthentication.csproj References MSAL for browser testing.
src/​Components/​test/​testassets/​Components.TestServer/​wwwroot/​msal-initialization.html Adds a concurrent-initialization browser test page.
src/​Components/​test/​E2ETest/​Tests/​RemoteAuthenticationTest.cs Checks initialization before and after refresh.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 16, 2026
@Youssef1313
Youssef1313 merged commit a135adb into main Oct 16, 2026
40 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/msal-init branch October 16, 2026 21:13
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed: bug fix restoring intended MSAL initialization behavior, with tests only otherwise.

Documentation surfaces considered

  • Conceptual article: Not required — Internal fix for an initialization race in MSAL interop; no public API, config, or documented behavior change.
  • Migration guidance: Not required — No upgrade action needed.
  • Breaking change: Not required — Restores intended behavior; no compatibility impact.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 7ca3b4e6 Deployed Oct 16, 2026 by Youssef1313 via conclusion #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants