sta / sta/websocket-sharp

Met StackOverflowException Exception when running websocket-sharp client inside docker container if server process is killed suddenly.

Open
#500 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

Hi websocket-sharp experts,

Thanks for providing this websocket lib so I can use it in my project. I met some issue which I could not solve myself, so I ask for help.

Scenario:
I use websocket-sharp in both my server/client part. when the socket connection was established, the server will do some job and notify client timely like the progress information, finally server will send the result to client as a serialized json string.
The server is base on .net framework 4.62 and the client is base on .net core 2.1.

How to trigger the issue:
After the connection is established, when I kill the server process suddenly:

  1. The client will not be aware of this. no event in OnError and on Event in Onclose.
  2. So I set a timer in server to send ping to client periodically, if client not received ping in a long time(say 3 times larger than the ping interval), client will think the socket is close and close the request in client it self.

`
var interval = 10000;

        timer = new Timer(callback =>
        {
            try
            {
                this.Context.WebSocket.Ping();
                timer.Change(interval, Timeout.Infinite);
            }
            catch
            {
                timer.Dispose();
            }
        },

            null, interval, Timeout.Infinite);

`

Issues:
The client is running fine in windows, but if I pack the .net core client inside a docker image, whenever running it in windows container using docker in windows or in linux container with Ubuntu, the container will be terminated and it will report error like:
Process is terminating due to StackOverflowException.

Analysis:
I have tried to increase the stack size(default is 8M) to 800M for the linux container by:
ulimit -s 819200

After increase the default stack size, the container will not terminated , but if we use 'docker stats' to see the container stats, it consume 100% CPU and almost 1GB memory and the resources are not released.

Debug:
I have debug the issue in windows with VS2017, the client process will not consume such much memory after kill the server process, but the websocket client seems will recursion deep in Ext.cs ReadBytesAsync function and it might cause the issue.

Questions:

  1. How to solve the issue?
  2. If server process is killed, any notification to the client socket?

Thank you.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Ext.cs ReadBytesAsync and trace the websocket client's receive path when the server process is killed. Reproduce the scenario with the .NET Core client in the reported Windows or Ubuntu container and inspect the timer-driven Ping behavior. Done means the failure no longer recurses until StackOverflowException or consumes unbounded CPU and memory, with the client's connection state or notification behavior understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.