jchristn/WatsonWebsocket

Nonexistent network connection error

Closed this issue · 7 comments

I am building a .net plugin with this great Websocket server tool.
The plugin opens up a websocket server and allows browser to connect and send messages through localhost:9000.
There is a very interesting case. If the user opens a coonection and close browser, which will disconnect, within about 25 seconds, it returns this error which can not be handled:
HttpListenerException: An operation was attempted on a nonexistent network connection
It eventually causes a crash.
Does anyone have the same experience?

Hi @zhangjinzhou thanks for your note.

Would you be able to reproduce after having set Logger on your server instance?

@jchristn How can I set Logger? Sorry I am not familiar with the package.

Hi @zhangjinzhou no problem, you can set it like this:

WatsonWsServer server = new WatsonWsServer(...);
server.Logger = Logger;

static void Logger(string msg)
{
  Console.WriteLine(msg);
}

Use whatever means you need/can in the Logger method to capture what's happening internally within the library.

@jchristn I still get the same error with the Logger added. BTW the error message is not logged. Here is a screenshot of the error in case you need.
image

Thanks @zhangjinzhou - I appreciate the insight. It appears this is happening inside of AcceptConnections. Out of curiosity, which operating system and framework are you using? Which browser are you using?

I just tested by using the Test.Server project under Windows 10, .NET 5.0, and Chrome 87, using the following code in an empty tab:

let socket = new WebSocket("ws://localhost:9000/test/");
socket.onopen = function () { console.log("success"); };
socket.onmessage = function (msg) { console.log(msg.data); };
socket.onclose = function () { console.log("closed"); };

After it connected, I closed the tab, and Test.Server correctly picked up the disconnect. However, it's been five minutes and I have yet to see a crash.

Could you help me reproduce with exact steps and versions etc? Thanks!

@jchristn We are using .net 4.0 on windows 10. The browser is chrome.
Do you have a clue about what the error message indicate?

Hi @zhangjinzhou I just tested on .NET Framework 4.5.2, and didn't encounter the issue. Do you experience the issue also with the Test.Server project?

The exception seems to be occurring in the AcceptConnections method within the server. If it's an issue in the library, it's likely something being stuck or hung that times out and causes the HTTP listener to panic, but that's just a guess.

Please let me know if you encounter the issue with the Test.Server project too. Cheers, Joel