aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

[Known Build Error] `NavigationException_InAsyncContext_DoesNotBecomeUnobservedTaskException` fails with `ObjectDisposedException`

Open ilonatommy opened this issue 6 months ago • 4 comments

The test should not be quarantined, it's under observation. It has a PR that tries to fix it and requires more investigation: https://github.com/dotnet/aspnetcore/pull/62662.

Build Information

Build: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1090989 Build error leg or test failing: Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.RedirectionTest.NavigationException_InAsyncContext_DoesNotBecomeUnobservedTaskException Pull request: https://github.com/dotnet/aspnetcore/pull/62602

Error Message

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

{
  "ErrorMessage": "A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}
     <h1>Hello, world!</h1><p id="unobserved-exceptions-count">4</p><h2>Unobserved Exceptions (for debugging):</h2>
        <ul><li>System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.
Object name: 'IServiceProvider'.)
 ---&gt; System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Components.Server.Circuits.CircuitPersistenceManager.PauseCircuitAsync(CircuitHost circuit, Boolean saveStateToClient, CancellationToken cancellation) in /home/vsts/work/1/s/src/Components/Server/src/Circuits/CircuitPersistenceManager.cs:line 25
   at Microsoft.AspNetCore.Components.Server.Circuits.CircuitRegistry.PauseAndDisposeCircuitHost(CircuitHost circuitHost, Boolean saveStateToClient) in /home/vsts/work/1/s/src/Components/Server/src/Circuits/CircuitRegistry.cs:line 312
   --- End of inner exception stack trace ---</li><li>

Known issue validation

Build: :mag_right: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1090989 Error message validated: [A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.] Result validation: :white_check_mark: Known issue matched with the provided build. Validation performed at: 7/11/2025 10:21:55 AM UTC

Report

Build Definition Step Name Console log Pull Request
1227683 dotnet/aspnetcore Run E2E tests Log dotnet/aspnetcore#64727
1206046 dotnet/aspnetcore Run E2E tests Log
1201403 dotnet/aspnetcore Run E2E tests Log

Summary

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

ilonatommy avatar Jul 11 '25 10:07 ilonatommy

A slightly different manifestation

OpenQA.Selenium.BrowserAssertFailedException : Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differ
Expected: 0
Actual:   7
   at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer) in /_/src/xunit.assert/Asserts/EqualityAsserts.cs:line 154
   at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass20_0.<WaitAssertCore>b__0() in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 91
   at Microsoft.AspNetCore.E2ETesting.WaitAssert.<>c__DisplayClass21_0`1.<WaitAssertCore>b__0(IWebDriver _) in /home/vsts/work/1/s/src/Shared/E2ETesting/WaitAssert.cs:line 109
Screen shot captured at '/home/vsts/work/1/s/src/Components/test/E2ETest/bin/screenshots/c71da8dad4a04a4492f6a7e869d3af97.png'
Encountered browser errors
[2025-07-24T15:53:25Z] [Warning] http://127.0.0.1:46627/subdir/_framework/blazor.web.tinuumbi1s.js 0:42467 "[2025-07-24T15:53:25.443Z] Warning: Initializer 'http://127.0.0.1:46627/subdir/BasicTestApp.vpc4xa0l6h.lib.module.js' will be ignored because multiple runtimes are available. Use 'before(Web|WebAssembly|Server)Start' and 'after(Web|WebAssembly|Server)Started' instead."
[2025-07-24T15:53:25Z] [Warning] http://127.0.0.1:46627/subdir/_framework/blazor.web.tinuumbi1s.js 0:42467 "[2025-07-24T15:53:25.452Z] Warning: Initializer 'http://127.0.0.1:46627/subdir/JSInitializers/Classic/BasicTestApp.j2kfp6tx1s.lib.module.js' will be ignored because multiple runtimes are available. Use 'before(Web|WebAssembly|Server)Start' and 'after(Web|WebAssembly|Server)Started' instead."
[2025-07-24T15:53:27Z] [Warning] http://127.0.0.1:46627/subdir/_framework/blazor.web.tinuumbi1s.js 0:42467 "[2025-07-24T15:53:27.959Z] Warning: Initializer 'http://127.0.0.1:46627/subdir/BasicTestApp.vpc4xa0l6h.lib.module.js' will be ignored because multiple runtimes are available. Use 'before(Web|WebAssembly|Server)Start' and 'after(Web|WebAssembly|Server)Started' instead."
[2025-07-24T15:53:27Z] [Warning] http://127.0.0.1:46627/subdir/_framework/blazor.web.tinuumbi1s.js 0:42467 "[2025-07-24T15:53:27.968Z] Warning: Initializer 'http://127.0.0.1:46627/subdir/JSInitializers/Classic/BasicTestApp.j2kfp6tx1s.lib.module.js' will be ignored because multiple runtimes are available. Use 'before(Web|WebAssembly|Server)Start' and 'after(Web|WebAssembly|Server)Started' instead."Page content:
<head><meta charset="utf-8">
    <base href="/subdir/">
    </head>
<body><nav><a href="nav">Home</a> |
    <a href="streaming">Streaming</a> |
    <a href="large-streaming">Large Streaming</a> |
    <a href="streaming-interactivity">Streaming with interactivity</a> |
    <a href="nav/give-404-with-content">Error page with 404 content</a> |
    <a href="nav/nonexistent-page">Error page with no content</a> |
    <a href="nav/non-html-response">Non-HTML page</a> |
    <a href="nav/non-blazor-html-response">Non-Blazor HTML page</a> |
    <a href="nav/scroll-to-hash#some-content">Scroll to hash</a> |
    <a href="nav/throw-while-streaming">Error while streaming</a> |
    <a href="nav/interactive-component-navigation/server">Interactive component navigation (server)</a> |
    <a href="nav/interactive-component-navigation/webassembly">Interactive component navigation (webassembly)</a> |
    <a href="nav/list-headers">List headers</a> |
    <a href="nav/preserve-content">Preserve content</a>
    <span data-enhance-nav="false"><a href="nav/other"><span id="not-enhanced-nav-link">Other (no enhanced nav)</span></a> |
        <span data-enhance-nav=""><a href="nav/other">Other (re-enabled enhanced nav)</a> |
        </span></span>
    <a href="nav/location-changed/server">LocationChanged/LocationChanging event (server)</a>
    <a href="nav/location-changed/wasm">LocationChanged/LocationChanging event (wasm)</a>
    <a href="nav/location-changed/server-and-wasm">LocationChanged/LocationChanging event (server-and-wasm)</a>
    <a href="nav/null-parameter/server">Null component parameter (server)</a>
    <a href="nav/null-parameter/wasm">Null compone

maraf avatar Jul 25 '25 08:07 maraf

Possible reasons for multiple PauseAndDisposeCircuitHost calls:

  • Race between eviction and manual termination - both OnEntryEvicted and TerminateAsync use circuitHost.DisposeAsync that cleans the scope of the circuit. Scenario: theoretically the circuit could be evicted due to expiration when at the same time, terminated manually.
  • Race between pause and terminate - both PauseCore and TerminateAsync use circuitHost.DisposeAsync. Scenario: circuit is paused while at the same time it's terminated e.g. due to unhandled exception.
  • Race between multiple pauses. Same as above but different combination.

First thing would be to consolidate disposal logic, now we have at least 3 code paths that can lead to disposal. I'm not sure if we could avoid some fire-and forget that introduced disposal that can race with other operations: https://github.com/dotnet/aspnetcore/blob/29f49f377aa7b2739a764e0aefe44b95d59f13d6/src/Components/Server/src/Circuits/CircuitHost.cs#L386, that's worth looking into.

ilonatommy avatar Jul 30 '25 12:07 ilonatommy

This should stay opened after merging https://github.com/dotnet/aspnetcore/pull/63010 which is a potential fix. I'm assigning @javiercn as a reminder to take another look before RTM to make sure it's working as expected.

ilonatommy avatar Aug 05 '25 09:08 ilonatommy

This is still being hit (~5x a day) after merging the initial fix attempt.

ilonatommy avatar Aug 21 '25 10:08 ilonatommy