Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PreventObjectDisposedException from becoming unobserved during circuit cleanup#62662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
ilonatommy wants to merge2 commits intodotnet:main
base:main
Choose a base branch
Loading
fromilonatommy:fix-persistent-state-throws-unobserved-exceptions

Conversation

ilonatommy
Copy link
Member

Issue similar to#62554.

log

[xUnit.net 00:20:37.86]     Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.RedirectionTest.NavigationException_InAsyncContext_DoesNotBecomeUnobservedTaskException [FAIL]  Failed Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.RedirectionTest.NavigationException_InAsyncContext_DoesNotBecomeUnobservedTaskException [36 s]  Error Message:   OpenQA.Selenium.BrowserAssertFailedException : Xunit.Sdk.EqualException: Assert.Equal() Failure: Values differExpected: 0Actual:   4<h1>Hello, world!</h1><p>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>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'.

Description

PeristanceManager.PauseCircuitAsync tries to resolve theComponentStatePersistenceManager service from an already disposed service provider during circuit cleanup (triggered by garbage collection), causing anObjectDisposedException to be thrown.

varpersistenceManager=circuit.Services.GetRequiredService<ComponentStatePersistenceManager>();

Theoretically we are subscribed tocircuitHost.UnhandledException but it did not get triggered in this situation. The fix is to observe the exception. I choseCircuitRegistry for it because it hasCircuitHost_UnhandledException method to handle that gracefully.

This failure was obsered once on CI, see the log above. Running that test locally on repeat did not reveal any hits after 1k runs.

@ilonatommyilonatommy added this to the10.0-preview7 milestoneJul 10, 2025
@ilonatommyilonatommy self-assigned thisJul 10, 2025
@ilonatommyilonatommy requested a review froma team as acode ownerJuly 10, 2025 15:13
@ilonatommyilonatommy added the area-blazorIncludes: Blazor, Razor Components labelJul 10, 2025
}
catch (ObjectDisposedException ex)
{
// Expected when service provider is disposed during circuit cleanup e.g. by forced GC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't understand this bit super well.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The test that was failing is forcing GC.


It looks like after that operation (that cleaned DI services), we are trying to do:
varpersistenceManager=circuit.Services.GetRequiredService<ComponentStatePersistenceManager>();

Which is throwing. I'm not sure how else we can get to such situations, if we don't force GC - which is not a common pattern. However, I don't see any harm letting the exception be observed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we want to track the root cause of the objectdisposedexception, as it might be pointing out a real issue. If you are able to reproduce it, can you capture the callstack for the object disposed exception?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I cannot reproduce it. I really tried, 1k runs locally and no failure

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you are able to reproduce it, can you capture the callstack for the object disposed exception

We could add more logging of inner exception in the test and count on it to fail again on CI. However, we don't know if it will be on a PR that someone will report the failure. Or will they just hit rerun and be happy that it passed the next time.

@ilonatommy
Copy link
MemberAuthor

The logging added in the previous commit is not that helpful - it's mostly duplication of current call stack printed in the log. I'll create an issue and we will observe the CI. We should come back to this PR to investigate f we are not calling dispose multiple times and why the exception happens.

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

@javiercnjaviercnjaviercn left review comments

Copilot code reviewCopilotAwaiting requested review from CopilotCopilot will automatically review once the pull request is marked ready for review

At least 1 approving review is required to merge this pull request.

Assignees

@ilonatommyilonatommy

Labels
area-blazorIncludes: Blazor, Razor Components
Projects
None yet
Milestone
10.0-preview7
Development

Successfully merging this pull request may close these issues.

2 participants
@ilonatommy@javiercn

[8]ページ先頭

©2009-2025 Movatter.jp