Skip to content

WebSocket.Dispose() throws exception if DefaultHttpContext.Uninitialize had been called in background #59772

@t1g0rs

Description

@t1g0rs

Is there an existing issue for this?

  • I have searched the existing issues

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.Status: Resolvedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions