fix: handle disposed socket on close attempt#1591
Open
ezhevita wants to merge 4 commits intoSteamRE:masterfrom
Open
fix: handle disposed socket on close attempt#1591ezhevita wants to merge 4 commits intoSteamRE:masterfrom
ezhevita wants to merge 4 commits intoSteamRE:masterfrom
Conversation
JustArchi
approved these changes
Oct 15, 2025
xPaw
reviewed
Oct 17, 2025
JustArchi
reviewed
Oct 26, 2025
Contributor
JustArchi
left a comment
There was a problem hiding this comment.
Should be sufficient, you don't need to release semaphore to dispose it.
xPaw
reviewed
Nov 28, 2025
| } | ||
|
|
||
| if (packet != null && packet.Length > 0) | ||
| if (!cancellationToken.IsCancellationRequested && socket.State == WebSocketState.Open) |
Member
There was a problem hiding this comment.
Will socket.Dispose close cleanly, or should it still let CloseAsync be called here?
xPaw
reviewed
Nov 28, 2025
| cts.Cancel(); | ||
| cts.Dispose(); | ||
| runloopTask = null; | ||
| semaphore.Wait(); |
Member
There was a problem hiding this comment.
I wouldn't mind an explanatory comment here as to what flow is happening in regards to the semaphore and the cancellation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #524.
Some investigation
Originally I had the following stacktrace for ArchiSteamFarm:
ConnectedWebSocketis 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.ClientWebSocketaccesses that property in 7 methods:SendAsync(+2 overloads),ReceiveAsync(+1 overload),CloseAsync,CloseOutputAsync.WebSocketContextcalls these methods in these cases:SendAsyncis called fromWebSocketContext.SendAsync<-WebSocketConnection.Send, which doesn't match our stacktrace,ReceiveAsyncis called fromReadMessageAsync, but theObjectDisposedExceptionis explicitly handled there,CloseAsyncseems to be the only suitable candidate.