Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XamlDirective stack overflow exception #10314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ThomasGoulet73
Copy link
Contributor

@ThomasGoulet73 ThomasGoulet73 commented Jan 18, 2025

Fixes #10313

Description

I changed MemberReflector.UnknownReflector to be thread safe by initializing the property from the static constructor instead of doing the lazy initialization manually. The static constructor of a type is guaranteed to be called only once.

See the issue for an explanation of the bug and how it's hit.

Customer Impact

Could fix a crash or weird behavior at runtime but it's very hard to hit (See issue).

Regression

No.

Testing

Used the repro in the issue which crashed before this PR and passes with this PR.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

@ThomasGoulet73 ThomasGoulet73 requested review from a team as code owners January 18, 2025 06:07
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jan 18, 2025
@miloush
Copy link
Contributor

miloush commented Jan 18, 2025

Wouldn't it be enough if you did

private static MemberReflector s_UnknownReflector;
internal static MemberReflector UnknownReflector => s_UnknownReflector ??= CreateUnknownReflector();

@h3xds1nz
Copy link
Member

Is there a reason why we're not keeping lazy-init, just making it TS instead?

@ThomasGoulet73
Copy link
Contributor Author

It was lazy because static fields only get assigned when necessary and in this case CreateUnknownReflector was only called on the first call to UnknownReflector and it was thread-safe because static constructors are thread safe.

I pushed a commit to change it to make the lazy init explicit and more clear.

@dipeshmsft dipeshmsft self-assigned this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack overflow exception when creating and using multiple instances of XamlDirective in parallel
4 participants