-
Notifications
You must be signed in to change notification settings - Fork 521
fix: handle disposed socket on close attempt #1591
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
base: master
Are you sure you want to change the base?
Conversation
JustArchi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be sufficient, you don't need to release semaphore to dispose it.
| } | ||
|
|
||
| if (packet != null && packet.Length > 0) | ||
| if (!cancellationToken.IsCancellationRequested && socket.State == WebSocketState.Open) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will socket.Dispose close cleanly, or should it still let CloseAsync be called here?
| cts.Cancel(); | ||
| cts.Dispose(); | ||
| runloopTask = null; | ||
| semaphore.Wait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't mind an explanatory comment here as to what flow is happening in regards to the semaphore and the cancellation.
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.