Skip to content

Conversation

ezhevita
Copy link
Contributor

Fixes #524.

Some investigation

Originally I had the following stacktrace for ArchiSteamFarm:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.WebSockets.ClientWebSocket'.
   at System.Net.WebSockets.ClientWebSocket.get_ConnectedWebSocket()
   at SteamKit2.WebSocketConnection.WebSocketContext.RunCore(HttpMessageInvoker invoker, TimeSpan connectionTimeout, CancellationToken cancellationToken)
   at SteamKit2.TaskExtensions.IgnoringCancellation(Task task, CancellationToken token)

ConnectedWebSocket is a private property and there is no mention of it in SteamKit codebase whatsoever, so there is definitely some method that got inlined and its stackframe was omitted.
ClientWebSocket accesses that property in 7 methods:

  • SendAsync (+2 overloads),
  • ReceiveAsync (+1 overload),
  • CloseAsync,
  • CloseOutputAsync.

WebSocketContext calls these methods in these cases:

  • SendAsync is called from WebSocketContext.SendAsync <- WebSocketConnection.Send, which doesn't match our stacktrace,
  • ReceiveAsync is called from ReadMessageAsync, but the ObjectDisposedException is explicitly handled there,
  • CloseAsync seems to be the only suitable candidate.

@xPaw xPaw requested a review from yaakov-h October 17, 2025 07:17
}
finally
{
semaphore.Release();
Copy link
Member

Choose a reason for hiding this comment

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

The semaphore needs to be disposed too

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ObjectDisposedException for websocket

3 participants