-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket.Dispose() throws exception if DefaultHttpContext.Uninitialize had been called in background #59772
Comments
|
While
Problem is during disposing, if webserver disposes httpcontext quicker, then code reaches end of |
Why are you manually calling The problem here is that you're disposing the websocket after cleaning up the Incorrect code: using var websocket = ...;
httpContext.Uninitialize(); Fixed code: {
using var websocket = ...;
}
httpContext.Uninitialize(); Or var websocket = ...;
websocket.Dispose();
httpContext.Uninitialize(); |
I'm not calling
In my opinion |
That sounds like you aren't waiting for cleanup before returning from your middleware. Which goes against the quote you grabbed from the docs
|
Is there an existing issue for this?
Describe the bug
When websocket is accepted and processed in background it could happen, that web server uninitialize DefaultHttpContext, causing ObjectDisposedException, when calling
websocket.Dispose()
Expected Behavior
calling Dispose does not throw exception
Steps To Reproduce
Simple repro, that works as expected in .net8.0, but throws exception in .net9.0
Exceptions (if any)
ObjectDisposedException at
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.DefaultHttpContext.Abort()
at Microsoft.AspNetCore.WebSockets.AbortStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.Net.WebSockets.ManagedWebSocket.DisposeCore()
at System.Net.WebSockets.ManagedWebSocket.Dispose()
.NET Version
9.0.101
Anything else?
No response
The text was updated successfully, but these errors were encountered: