Skip to content

Conversation

@janvorli
Copy link
Member

The check is not correct and results in FailFast when a second thread tries to call this method. The previousCrashingThreadId is always the s_crashingThreadId for the second and following threads hitting this method. The correct check is to compare the currentThreadId with the s_crashingThreadId.

Close #119731

The check is not correct and results in FailFast when a second thread
tries to call this method. The `previousCrashingThreadId` is always the
`s_crashingThreadId` for the second and following threads hitting this method.
The correct check is to compare the `currentThreadId` with the `s_crashingThreadId`.

Close dotnet#119731
@janvorli janvorli added this to the 10.0.0 milestone Sep 15, 2025
@janvorli janvorli requested a review from jkotas September 15, 2025 19:39
@janvorli janvorli self-assigned this Sep 15, 2025
Copilot AI review requested due to automatic review settings September 15, 2025 19:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug in the recursion detection logic for AppContext.OnUnhandledException that was causing incorrect FailFast crashes when multiple threads called the method concurrently.

Key Changes

  • Corrected the recursion check by comparing currentThreadId against s_crashingThreadId instead of comparing s_crashingThreadId against previousCrashingThreadId
  • This prevents false positive recursion detection when different threads call OnUnhandledException

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

I am wondering whether it is worth it to write a regression test.

@AaronRobinsonMSFT
Copy link
Member

Deferring to #120069

@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for recursion in calls to AppContext.OnUnhandledException is incorrect

5 participants