doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

TCP socket send timout #242

Open Jakobi-mirsk opened 2 years ago

Jakobi-mirsk commented 2 years ago

hi I can see that when the server is terminated the client EmitAsync throws an abort exception. This is good, but it takes 30 seconds for it to abort the request. I guess it has something to do with the TCP send timeout. Is there any way to change the timeout of the TCP socket, so I get the exception faster? The reason is that, the server that I connect to, has a load balancer in front of it. So the load balancer has many servers behind it and some times a server crashes and if I am connected to that one, I need to reconnect right away. The socketIO should do the reconnect for me, but it doesn't. I have tried waiting several minutes for it to reconnect. I think it is because I send many request pr. second, so it is the send routine that detect that the connection is down and not socketIO. To reproduce I create a connection to a server and send something every 100ms. While the client is sending, the server is terminated the hard way (NOT gracefully) and client never reconnects. These are my socket options: options.Reconnection = true; options.ReconnectionAttempts = int.MaxValue; options.ReconnectionDelay = 100; options.ReconnectionDelayMax = 1000; options.RandomizationFactor = 0.5;

doghappy commented 2 years ago

Perhaps, you can set a timeout

var cts = new CancellationTokenSource(3000);
await socket.EmitAsync("hi", cts.Token, DateTime.Now.ToString());
Jakobi-mirsk commented 2 years ago

Do you think a version will become available at some point, with the option to specify a send timeout for the TCP socket?