Skip to content

Hang calling Environment.FailFast on multiple threads at the same time #72565

Closed

Description

@jkotas

dotnet run -c Release on .NET 6.0

class Test
{
    static void Main()
    {
        new Thread(GCWork).Start();

        for (int i = 0; i < 3; i++) new Thread(FailFastWork).Start();
        for (int i = 0; i < 10_000_000; i++) GC.KeepAlive(new object());

        flag = 1;

        for (;;) GC.KeepAlive(new object());
    }

    static volatile int flag;

    static void GCWork()
    {
        for (;;)
        {
            GC.Collect();
            Thread.Sleep(1);
        }
    }

    static void FailFastWork()
    {
        Recursion<int>(500);
    }

    static void Recursion<T>(int i)
    {
        if (i > 0) Recursion<T>(i - 1);
        while (flag == 0) { }
        Environment.FailFast("Crash");
    }
}

Activity

  1. ghost added
    untriaged
    on Jul 21, 2022
  2. added and removed
    untriaged
    on Jul 21, 2022
  3. added a commit that references this issue on Jul 21, 2022
    dfffa9f
  4. ghost added
    in-pr
    on Jul 21, 2022
  5. added a commit that references this issue on Jul 21, 2022
    78b44ea
  6. added a commit that references this issue on Jul 21, 2022
    dcf2c76
  7. ghost removed
    in-pr
    on Jul 21, 2022
  8. danmoseley commented on Jul 21, 2022

    @danmoseley
    Contributor

    Is any test feasible here? ie., can the above just turn into a test that should no longer hang?

  9. jkotas commented on Jul 21, 2022

    @jkotas
    MemberAuthor

    The repro that I have created was manually tweaked to repro the problem in .NET 6. It does not repro the problem in .NET 7 due to the timing and runtime implementation details changing in .NET 7.

    We have two tests exercising the paralel crash already: https://github.com/dotnet/runtime/tree/main/src/tests/baseservices/exceptions/simple

    And we have two issues opened on the intermittent failures (including timeouts/hangs) hit by the existing tests: #56950 #57621 . I think that it is pretty good chance that some of the intermittent failures tracked by these two issues are dups of this one.

  10. added a commit that references this issue on Aug 12, 2022
    0f6284e
  11. ghost locked as resolved and limited conversation to collaborators on Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions