.Connect hangs if server is down
Hi,
If you have your code like this,
DDPClient client = new DDPClient(sub); client.Connect("xxx.xxx.xxx.xxx:3000");
client.Connect will hang if, at the time, the server is down.
Do you know how this situation should be handled?
Thanks
Current state
Indeed. Current code cannot behave differently.
There is a busy waiting loop as seen on
public void Connect(string url, bool keepAlive = true, bool useSsl = false)
{
...
_socket.Open();
_isWait = 1;
this._wait();
}
_isWait is changed on socket opened event, and polled in DDPClient.NET/DDPConnector.cs at 94547061254aae2ffe3b96fb2351b4e090bcc444 · sonyarouje/DDPClient.NET line 79
private void _wait()
{
while (_isWait != 0)
{
System.Threading.Thread.Sleep(100);
}
}
What to do
Do you know how this situation should be handled?
At the very least, the _wait() implementation should be changed accept a timeout.
Best would be to rearchitecture with an asynchronous/event-oriented/reactive design. But it is a significant change and effort.
This bug appears to be solved on OzTK/DDPClient.NET: A DDP client for .NET
DDPClient.NET/DDPConnector.cs at 62d5a69c805b2b125984c6c070a0a845879a465b · OzTK/DDPClient.NET
private void Wait()
{
while (_isWait != 0 && _socket.State == WebSocketState.Connecting)
{
System.Threading.Thread.Sleep(100);
}
}