Skip to content

Runtime crash caused by Thread internal calls called on resurrected Thread #107473

Open

Description

@jkotas

Deterministic repro

  1. Build a private coreclr.dll with Sleep(1000) added here:
  2. Enable page heap for corerun.exe using gflags
  3. Compile and run the following test using corerun.exe:
using System;
using System.Threading;
using System.Runtime.CompilerServices;

Helper.Initialize();

new Thread(Work).Start();

GC.Collect();
GC.WaitForPendingFinalizers();

Thread.Sleep(3000);
	
static void Work()
{
   for (;;)
   {
       if (Helper.ResurectedThread != null)
       {
           Helper.ResurectedThread.DisableComObjectEagerCleanup();
       }
   }
}

class Helper
{
    public static volatile Thread ResurectedThread;

    Thread _thread;
 
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void Initialize() => GC.KeepAlive(new Helper());

    Helper()
    {
        _thread = new Thread(() => { });
        _thread.Start();
        _thread.Join();
    }

    ~Helper()
    {
        ResurectedThread = _thread;
    }
}

(It is also possible to build non-deterministic repro that reproduces the crash on shipping bits.)

Actual result

Assert failure(PID 23336 [0x00005b28], Thread: 21216 [0x52e0]): Consistency check failed: AV in clr at this callstack:
------
CORECLR! DoJoin + 0x2C3 (0x00007ffa`175c9d83)
CORECLR! ThreadNative_Join + 0x15B (0x00007ffa`175cd87b)
-----
.AV on tid=0x52e0 (21216), cxr=0000009F9477E6C0, exr=0000009F9477EBB0

The crash is caused by use-after-free of the unmanaged Thread object.

Expected result

No runtime crash. C# code that does not used unsafe blocks and that does not call any memory unsafe APIs should not lead to runtime crash.

Activity

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Sep 6, 2024
  2. jkotas commented on Sep 6, 2024

    @jkotas
    MemberAuthor

    The problem is not limited to Thread.Join. Majority of Thread APIs that are implemented using FCalls or QCalls suffer from this issue.

  3. added and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Sep 6, 2024
  4. dotnet-policy-service commented on Sep 6, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @mangod9
    See info in area-owners.md if you want to be subscribed.

  5. removed
    untriagedNew issue has not been triaged by the area owner
    on Sep 18, 2024
  6. added this to the 10.0.0 milestone on Sep 18, 2024
  7. mangod9 commented on Aug 13, 2025

    @mangod9
    Member

    @jkotas since this is not a regression, ok to move to 11?

  8. modified the milestones: 10.0.0, 11.0.0 on Aug 13, 2025
  9. jkoritzinsky commented on Jul 22, 2026

    @jkoritzinsky
    Member

    Fixed by #117788

  10. changed the title [-]Runtime crash caused by Thread.Join called on resurrected Thread[/-] [+]Runtime crash caused by Thread internal calls called on resurrected Thread[/+] on Aug 16, 2026
  11. jkotas commented on Aug 16, 2026

    @jkotas
    MemberAuthor

    Fixed by #117788

    This fixed the Thread.Join by rewriting it in C#. The problem remains for most existing Thread QCalls and FCalls (#107473 (comment))

    I have updated the title and repro

  12. reopened this on Aug 16, 2026
  13. added a commit that references this issue on Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions