Skip to content

ProcessTreeCpuSamplerTests.Finds_A_Real_Child_Process_Until_It_Exits fails on Windows: exited child's ID still reported #7909

Done

Description

@thomhurst

Summary

ProcessTreeCpuSamplerTests.Finds_A_Real_Child_Process_Until_It_Exits failed on a Windows CI runner: after the sort child exited and was disposed, a second TryRead still returned its process ID. The test asserts that ID is absent, so it fails whenever Windows still reports that ID as one of our descendants after exit. The change under test in that PR did not touch the sampler or this test.

Where

failed Finds_A_Real_Child_Process_Until_It_Exits (382ms)
  AssertionException: Expected to not contain 8228
  but the item was found in the collection
  at Assert.That(processes.Keys).DoesNotContain(childId)

Likely causes

Either is consistent with the failure; neither is excluded by the reader or the test today:

  1. The exited process is still visible. A Windows process object persists while any handle to it stays open, and GetProcessTimes succeeds on an exited process. The reader does not check whether a process is still running (GetExitCodeProcess / STILL_ACTIVE), so a lingering handle (another component's, or antivirus on the runner) keeps the ID in the result.
  2. The ID was reused. Windows reuses process IDs quickly. Other tests in TUnit.UnitTests start child processes in parallel, so the ID can belong to a new descendant created after ours. The test checks only the ID, not the start time it saw first.

Reproduction

Not deterministic. Run TUnit.UnitTests on a loaded Windows machine with tests in parallel; the failure needs the child's ID to stay listed after WaitForExitAsync returns.

Expected

The test fails only when the reader reports a process that has really exited. Suggested fix: compare by identity rather than by ID alone (assert no entry has the child's ID and its first-seen StartTime), and have the Windows reader skip processes whose exit code is no longer STILL_ACTIVE.

Can the reader be changed to drop exited processes, and the test to match on start time as well as ID?

Activity

  1. added
    bug
    on Nov 29, 2026
  2. added
    P2
    on Nov 29, 2026
  3. thomhurst commented on Nov 29, 2026

    @thomhurst
    OwnerAuthor

    Seen again on modularpipeline (windows-latest) for #7910: https://github.com/thomhurst/TUnit/actions/runs/46312567345/job/141502077944 (Expected to not contain 9276 but the item was found in the collection, at ProcessTreeCpuSamplerTests.cs:481). The machine was at 100% CPU at the time.

  4. thomhurst commented on Nov 29, 2026

    @thomhurst
    OwnerAuthor

    Seen again on PR #7898 (run 46314133323, modularpipeline windows-latest): Finds_A_Real_Child_Process_Until_It_Exits failed with "Expected to not contain 3704". It is unrelated to that PR's change. I reran the failed job.

  5. thomhurst commented on Nov 30, 2026

    @thomhurst
    OwnerAuthor

    Seen again on windows-latest, in modularpipeline (windows-latest) for PR #7916 at commit 17e55de864: https://github.com/thomhurst/TUnit/actions/runs/46496165319/job/142121980571

    failed Finds_A_Real_Child_Process_Until_It_Exits (230ms)
      AssertionException: Expected to not contain 9400
      but the item was found in the collection
      at Assert.That(processes.Keys).DoesNotContain(childId)
        at TUnit.UnitTests.ProcessTreeCpuSamplerTests.Finds_A_Real_Child_Process_Until_It_Exits() in tests/TUnit.UnitTests/ProcessTreeCpuSamplerTests.cs:512
    

    It was the only failure of 1,447 tests in TUnit.UnitTests (net10.0) in that job. That PR does not change ProcessTreeCpuSampler, its readers or this test.

  6. added a commit that references this issue on Nov 30, 2026
    06c7b9d
  7. thomhurst commented on Nov 30, 2026

    @thomhurst
    OwnerAuthor

    Failed again on PR #7916 at 609fc3bf76 (https://github.com/thomhurst/TUnit/actions/runs/46503201172/job/142146430947, Expected to not contain 3076), the second run in a row there. That PR now carries the fix in 06c7b9d: WindowsProcessTreeReader.TryReadTimes skips a process whose exit time is set, and the test compares the start time as well as the ID. This issue can close when #7916 merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions