Giter Site home page Giter Site logo

Comments (10)

zllvm avatar zllvm commented on May 20, 2024 1

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.

jchristn avatar jchristn commented on May 20, 2024

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.

zllvm avatar zllvm commented on May 20, 2024

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.

jchristn avatar jchristn commented on May 20, 2024

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.

zllvm avatar zllvm commented on May 20, 2024

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 on Receive always implies a connection loss?

Likewise, what do you think about configuring the ConnectedMonitor task so it can be optionally disabled?

from supersimpletcp.

Energiz0r avatar Energiz0r commented on May 20, 2024

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.

Espen-Kalhagen-Element-Logic avatar Espen-Kalhagen-Element-Logic commented on May 20, 2024

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.

jchristn avatar jchristn commented on May 20, 2024

Hi, I will take a look today. Cheers

from supersimpletcp.

jchristn avatar jchristn commented on May 20, 2024

Hi, could you please try v3.0.7?

NuGet: https://www.nuget.org/packages/SuperSimpleTcp/3.0.7
Commit: 825c017

from supersimpletcp.

jchristn avatar jchristn commented on May 20, 2024

Please re-open if this doesn't address the issue. Cheers!

from supersimpletcp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.