-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Stack overflow exception in Websocket.Client library #65
Comments
Thanks @spudwebb Looks like I'll need to include the source in to the binary to address it (and to cash in on the benefits). I'll ping you once tested |
Seems trying to bend the latest socket client to net standard 2.0 is more challenging than I thought. |
@marcus-j-davies I think 4.6.1 was this commit: Marfusios/websocket-client@638cf7f I had to open and build the project with VS 2019 though, using VS 2022 gave me build errors. |
I have managed to compile the latest socket client source code with
If I attach the I am not sure if surprises are awaiting, but I don't have the means to test this currently |
yes, I think I can test the |
OK, see this branch: https://github.com/zwave-js/ZWaveJS.NET/tree/bump-schema-%2B-Embed-Socket-Client-%2B-LR Depending on how successful this is, I will continue to bump the schema it now directly references some libs used by the socket client, as well as conditionally references some other libs to provide support for |
@marcus-j-davies, it doesn't work as is, the received messages from the websocket is always a bunch of 0. I changed the code in private async Task Listen(WebSocket client, CancellationToken token)
{
Exception? causedException = null;
try
{
// define buffer here and reuse, to avoid more allocation
const int chunkSize = 1024 * 4;
var buffer = new byte[chunkSize];
do
{
// ValueWebSocketReceiveResult result;
WebSocketReceiveResult result;
var ms = (RecyclableMemoryStream)_memoryStreamManager.GetStream();
ArraySegment<byte> bufferSegment = new ArraySegment<byte>(buffer);
while (true)
{
result = await client.ReceiveAsync(bufferSegment, token);
ms.Write(buffer, 0, result.Count);
if (result.EndOfMessage)
break;
} with this change it seems to work, but honestly I'm not super confortable using this version in production as it was not designed to work on |
Hi @spudwebb I think I agree - feels a bit desperate, leave it with me, as I will work on adding LR support. |
Fixed in v4 |
I get a stack overflow crash in our program by doing this:
driver.Destroy()
=> a
StackOverflowException
occurs inClientWebSocket.Dispose()
It is 100% reproducible in our program, but I wasn't able to reproduce it with a simple console program, so I must be missing something there.
Anyway, I have traced down the problem to be related to this issue in the Websocket.Client library: Marfusios/websocket-client#124
While debugging in VS, if you "break all" while waiting in step 3 from above, you can see the hundred of recursive calls in the task used for reconnection.
A fix for this problem has been implemented in recent version of the Websocket.Client library, but unfortunately this version has dropped support for
netstandard2.0
, so we cannot directly update the library from nuget unless netstandard2.0 is dropped in ZWaveJS.NET as well, which is out of question for us because our program still use .NET Framework.So I'm not sure how to best fix this issue?
For now, I pulled the source code for Websocket.Client version 4.6.1 (the version currently used by ZwaveJS.NET) and I manually merged the fix for the recursive call problem: Marfusios/websocket-client@df2e007
I successfully tested that it fixes my stack overflow problem.
The text was updated successfully, but these errors were encountered: