Skip to content

.NET 6 Blazor server app not Disposing razor pages on browser tab close #39370

Closed
@jeffraska

Description

@jeffraska

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When IDisposable is implemented in razor page and browser tab is closed by user, the Dispose method is called after few minutes and not immediately after tab close.
The very first thing I'd mention is that disposing of razor pages worked correctly in .NET 5 so apparently it's a bug in .NET 6 (or ASP.NET Core Runtime). Problem started to appear after I've upgraded my project to .NET 6.

This problem was discused previously in https://github.com/dotnet/aspnetcore/issues/38147 but solution in answer does not solve this problem - .NET knows about tab being closed but just do not call Dispose.

Expected Behavior

When browser tab is closed .NET should dispose all razor pages that existed in this session.

Steps To Reproduce

  1. Create Blazor server app according to https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/create
  2. Implement IDisposable in Counter.razor and set breakpoint in Dispose method
  3. Add HubFilter using builder.Services.Configure<HubOptions>(O => O.AddFilter<HubFilter>()); and set breakpoint in OnDisconnectedAsync
  4. Start app and navigate to /counter
  5. Close tab
  6. OnDisconnectedAsync is called but Dispose is not.

Exceptions (if any)

No response

.NET Version

6.0.101

Anything else?

No response

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