pusher / pusher-websocket-dotnet

Pusher Channels Client Library for .NET
MIT License
112 stars 113 forks source link

The application hangs if connection fails. #7

Closed RobertoSchneiders closed 4 years ago

RobertoSchneiders commented 9 years ago

I created a simple console application that subscribes to a channel. When I disable the connection to simulate a connection failure Pusher Client tries desperately to reconnect and after some seconds he hangs.

Hangs with "conecting" status. That is the log:

Connection state: Disconnected
Connection state: Connecting
Pusher Error: 0 : Error: System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
Pusher Warning: 0 : Websocket connection has been closed
Connection state: Disconnected
Connection state: Connecting
Pusher Error: 0 : Error: System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
Pusher Warning: 0 : Websocket connection has been closed
Connection state: Disconnected
Connection state: Connecting

ProcessExplorer shows the resource consuming. image

RobertoSchneiders commented 8 years ago

Does anyone have any idea what might be causing this?

I changed this:

if(_allowReconnect)
    Connect();

for this:

if (_allowReconnect)
{
    Thread.Sleep(250);
    ChangeState(ConnectionState.Connecting);
    _websocket.Open();
}

on Connection.cs

The idea was to avoid the Connect() overhead (reacreating objects) and try to do less retry attempts (with the sleep).

improved slightly, but did not solve the problem. With this code, sometimes it takes a few minutes to crash (current version hangs in seconds).

leggetter commented 8 years ago

@RobertoSchneiders - could you please try out the latest version from source (master) and let me know how you get on?

The example application has also been updated and should result in simplified setup code: connections and subscriptions. See https://github.com/pusher-community/pusher-websocket-dotnet/blob/master/ExampleApplication/Program.cs#L48-L70

RobertoSchneiders commented 8 years ago

The example application has also been updated and should result in simplified setup code: connections and subscriptions.

Great!

could you please try out the latest version from source (master) and let me know how you get on?

I made some tests using the master branch @leggetter. Results are pretty much the same to those tests with the code I posted above. Unfortunately, not so good.

Connection state: Disconnected
Connection state: WaitingToReconnect
Connection state: Connecting
Pusher Information: 0 : Connecting to: ws://pusher.my_domain.com.br/app/monde?protocol=5&client=pusher-dotnet-client&version=0.0.1
Connection state: Connecting

Crashed in 1m45s.

Today was released the WebSocket4Net 0.14.0, but the results are the same. :/

If you have any idea of the cause of this problem, I can try to fix it, or at least test it for you.

[off-topic] There are some reason for websocket.AutoSendPingInterval be 1? (code) The default value is 60s. I'll have a lot of connections, so, every request counts.

damdo commented 4 years ago

Fixed by #95