Closed
Description
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
- Create Blazor server app according to https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/create
- Implement IDisposable in Counter.razor and set breakpoint in Dispose method
- Add HubFilter using
builder.Services.Configure<HubOptions>(O => O.AddFilter<HubFilter>());
and set breakpoint in OnDisconnectedAsync - Start app and navigate to /counter
- Close tab
- OnDisconnectedAsync is called but Dispose is not.
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
No response