Fix MacMainThreadScheduler crash when ManagedThreadId != 1 (#646)#649
Open
Fix MacMainThreadScheduler crash when ManagedThreadId != 1 (#646)#649
Conversation
Contributor
Author
|
validated on linux-x64, win x64, arm64. Need to finialze mac testing |
Contributor
Author
|
finished mac testing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #646 — MacMainThreadScheduler.StartMessageLoop() throws "Message loop must be started on the main thread" when Environment.CurrentManagedThreadId is not 1, which can happen when launched via dotnet tool run or dotnet run where internal runtime threads consume thread ID 1 before Main() executes.
MSAL's MacMainThreadScheduler assumes ManagedThreadId == 1 means "main thread." This is a .NET runtime implementation detail, not a guarantee. The dotnet tool shim and certain hosting configurations cause Main() to run on a thread where this check fails.
This change proposes falling back to no longer use the MacMainThreadScheduler when the thread != 1. Windows and Linux brokers will be unaffected, but mac broker will become unavailable and fall back to browser or DCF.