Comments (10)
I've done the following change in PollSocket
method:
catch (SocketException ex)
{
Logger?.Invoke($"{Header}poll socket from {ServerIpPort} failed with ex = {ex}");
return ex.SocketErrorCode == SocketError.TimedOut;
}
After that, I deployed it to the dev server and started a TCP connection that has been up and running for two days with no issues. I could test it by running various commands on the open connection, which worked perfectly. The log entry that I've added $"{Header}poll socket from {ServerIpPort} failed with ex = {ex}"
appeared several time times (~20) in the monitoring system with Operation timed out exception
.
Evidently, PollSocket
introduces a harmful behavior by disconnecting an existing connection. I don't know if it is possible to make it fully reliable. If not, then it should be allowed to override or disable it.
What is your opinion on this, @jchristn? Could we re-open this issue?
from supersimpletcp.
Do you have TCP keepalives enabled on either client or server? I don't suspect there is an issue in the implementation, but if you can point to one, I'd love a PR with a fix!
from supersimpletcp.
I have keepalive enabled on the client but not on the test server. I've found another issue where you explain that keepalives can bring odd behavior. I can disable them and see if it helps.
It is worth mentioning that I cannot reproduce this issue on my windows pc, and it fails in the ci pipe that executes in a Linux environment (mcr.microsoft.com/dotnet/sdk:6.0-alpine). Therefore, it seems more likely to be something related to keepalives.
This issue can be closed, I suppose. And if I find a problem in the library code that I can fix, I'll do a PR as you suggest. Thanks!
from supersimpletcp.
Hi @zllvm TCP keepalives are the bane of my existence (at least with these libraries...). I have unfortunately zero control over them, and they only exist to solve a very niche problem (cable removed from switch or router) and it often doesn't even do a good job of solving that, not to mention they seemingly introduce random problems everywhere. Please let me know if disabling them helps. Please re-open if the problem continues with keepalives disabled! Cheers, Joel
from supersimpletcp.
Hi @jchristn! Aw, I understand your pain!
It works much better with keepalives disabled, though it still disconnects occasionally. I started to debug it by increasing logging in your library. It turns out that it fails on:
var clientSentData = _client.Client.Receive(buff, SocketFlags.Peek) != 0;
with System.Net.Sockets.SocketException (110): Operation timed out
After that, the connection is forcefully closed by ConnectedMonitor
. Nevertheless, I'm pretty sure that the connection is still alive.
If I understand it correctly, Receive
is called in a non-blocking mode and therefore throws SocketException
when there's no data according to the microsoft doc. In this document, it's suggested to check the Available
property to know if there's data.
Thereby, I realized that I don't fully comprehend the logic in PollSocket
:
- If no data is available at a specific moment, how could
Receive
indicate a connection problem? - Can we be sure that
SocketException
onReceive
always implies a connection loss?
Likewise, what do you think about configuring the ConnectedMonitor
task so it can be optionally disabled?
from supersimpletcp.
FYI: We are having the exact same issue in our environment here.
Works stable when testing this on windows, but as soon as we deploy this to our Ubuntu server, disconnections start with Timeout 110 error.
from supersimpletcp.
FYI: We are having the exact same issue in our environment here. Works stable when testing this on windows, but as soon as we deploy this to our Ubuntu server, disconnections start with Timeout 110 error.
I work with Energiz0r.
We need to use SuperSimpleTcp with the changes suggested by @zllvm, returning true if the exception is a timeout exception, to achieve stable tcp connections.
from supersimpletcp.
Hi, I will take a look today. Cheers
from supersimpletcp.
Hi, could you please try v3.0.7?
NuGet: https://www.nuget.org/packages/SuperSimpleTcp/3.0.7
Commit: 825c017
from supersimpletcp.
Please re-open if this doesn't address the issue. Cheers!
from supersimpletcp.
Related Issues (20)
- keepalive is not working on win7 HOT 1
- keepalive option HOT 4
- Message Framing Question HOT 1
- Send(); fails on Windows 8/8.1 HOT 2
- SimpleTcpServer DataReceived method spawns a new task for each DataReceived event HOT 3
- receive data not fast after connect HOT 1
- Server.IsListening wrong behavior when MaxConnections reached HOT 1
- how to include dll file in exe file to be a one exe file ?? HOT 1
- NoDelay option for listener HOT 1
- KeepAliveSettings for server are applied in seconds on connecting client instead of ms HOT 1
- An active client with keep alive that does not process incoming message leads memory buildup in the server HOT 1
- What metadata is being embeded when the data is send in chunks? HOT 1
- SimpleTcpClient.Events.Disconnected is not triggered when SimpleTcpServer.Close() is invoked. HOT 1
- Block Unwanted Participants HOT 1
- multiple IP address HOT 2
- Keep Alive in linux container HOT 1
- The server sends messages to all clients on a regular basis HOT 2
- The client connecting to the Server on Maui is immediately kicked out. HOT 17
- About _Server.Stop() HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supersimpletcp.