Skip to content

StartCanBeCancelled fails with assertion #125937

Closed

Description

@danmoseley

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1346843
Build error leg or test failing: Microsoft.Extensions.Hosting.Internal.HostTests.StartCanBeCancelled
Pull request: https://github.com/dotnet/runtime.git/pull/125912

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": ["StartCanBeCancelled","Assert.True()"],
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}
Exception Message
Assert.True() Failure
Expected: True
Actual:   False
CallStack
   at Microsoft.Extensions.Hosting.Internal.HostTests.<StartCanBeCancelled>d__13.MoveNext() in /_/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:line 297
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1346843
Error message validated: [StartCanBeCancelled Assert.True()]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 3/23/2026 12:52:32 AM UTC

Report

Build Definition Test Pull Request
1346843 dotnet/runtime Microsoft.Extensions.Hosting.Internal.HostTests.StartCanBeCancelled #125912

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
1 1 1

Activity

  1. added
    blocking-clean-ci
    Known Build Error
    on Mar 23, 2026
  2. added
    untriaged
    on Mar 23, 2026
  3. danmoseley commented on Mar 23, 2026

    @danmoseley
    ContributorAuthor

    older issue #106135

    edit: oops that looks like Core, this is net481-windows-Release-x86-NET481_Release-Windows.10.Amd64.Client.Open

  4. dotnet-policy-service commented on Mar 23, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-extensions-hosting
    See info in area-owners.md if you want to be subscribed.

  5. danmoseley commented on Mar 23, 2026

    @danmoseley
    ContributorAuthor

    Note

    This analysis was generated with AI assistance (GitHub Copilot).

    Analysis

    Failing assertion: Line 296: Assert.True(serviceStarting.WaitOne(TimeSpan.FromSeconds(5))). The stack trace reports "line 297" because .NET Framework's async state machine PDB mapping is off by one — line 297 is cts.Cancel() which cannot throw Assert.True() Failure.

    What it means: host.StartAsync() didn't reach the FakeHostedService.StartAction callback within 5 seconds. Looking at Host.StartAsync, before it reaches the hosted service's StartAsync it must:

    1. await _hostLifetime.WaitForStartAsync()
    2. Resolve IEnumerable<IHostedService> from DI
    3. await ForeachService for StartingAsync lifecycle hooks
    4. Then await ForeachService for StartAsync → FakeHostedService.StartAction → sets serviceStarting

    Each ConfigureAwait(false) continuation needs a ThreadPool thread.

    Why .NET Framework 4.8.1 specifically:

    • Framework's ThreadPool ramps threads slowly (~500ms per new thread beyond min threads)
    • Test runs with parallel test collections = on [2 threads] — other hosting tests compete for ThreadPool threads
    • x86 process has smaller default min ThreadPool size
    • Framework async state machines have more overhead per continuation

    Relationship to #106135: Same test, same symptom, but different context:

    Fix options: Increase the 5s timeout to 30s (consistent with other hosting tests that were already bumped — see PR #43695, #59811), or replace ManualResetEvent with TaskCompletionSource-based async signaling to avoid hard timeouts entirely.

  6. danmoseley commented on Mar 23, 2026

    @danmoseley
    ContributorAuthor

    Note

    This analysis was generated with AI assistance (GitHub Copilot).

    Why this test specifically?

    All three Task.Run(() => host.StartAsync(...)) + WaitOne(5s) tests in HostTests.cs are structurally similar, but they signal at different points in the Host.StartAsync pipeline:

    • HostLifetimeOnStartedDelaysStart and HostLifetimeOnStartedCanBeCancelled signal during step 1 — _hostLifetime.WaitForStartAsync() — the very first await in Host.StartAsync.

    • StartCanBeCancelled signals during step 4 — inside ForeachService for StartAsync → FakeHostedService.StartAction. To get there, Host.StartAsync must first:

      1. await WaitForStartAsync
      2. Resolve IEnumerable<IHostedService> from DI
      3. await ForeachService for StartingAsync lifecycle hooks
      4. await ForeachService for StartAsync → signal fires here

    Each ConfigureAwait(false) continuation requires a ThreadPool thread on .NET Framework. StartCanBeCancelled needs more async hops before the event fires, making it the most susceptible to ThreadPool pressure on the NET481 leg (x86, Framework ThreadPool ramps slowly at ~500ms/thread, 2 parallel test collections).

  7. danmoseley commented on Mar 23, 2026

    @danmoseley
    ContributorAuthor

    @copilot bump timeout for this specific test as suggested. your PR should close this issue

  8. removed
    untriaged
    on Mar 23, 2026
  9. locked and limited conversation to collaborators on Apr 23, 2026
  10. added this to the 11.0.0 milestone on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Known Build Errorarea-Extensions-Hostingblocking-clean-ci

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions