Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session state not cleared/updated on disconnect without the Logout message (i.e. when SocketException is raised) #898

Open
GorJer opened this issue Nov 15, 2024 · 3 comments

Comments

@GorJer
Copy link

GorJer commented Nov 15, 2024

Hi,

We have notice following issue:

  • Initiator Session connected and logged on
  • At some point remote side disconnects (no logout), which results in SocketException (SocketError.ConnectionReset)
  • This results in SocketInitiatorThread.Disconnect() method being called
  • Unfortunately the Session itself is not being touched
  • The result is that Session is in incorrect state => Session.IsLoggedOn will still return true and Session.Application is not aware of the session going down)

A small change in SocketInitiatorThread.Read() method's exception handling would fix the issue, it will reset the session and call Application.OnLogout():

public bool Read()
{
    try
    {
        int bytesRead = ReadSome(_readBuffer, 1000);
        if (bytesRead > 0)
            _parser.AddToStream(_readBuffer, bytesRead);
        else
            Session.Next();

        ProcessStream();
        return true;
    }
    catch (ObjectDisposedException)
    {
        // this exception means _socket is already closed when poll() is called
        if (_isDisconnectRequested == false)
            Disconnect();
    }
    catch (Exception e)
    {
        Session.Log.OnEvent(e.ToString());
        if (!Session.HasResponder)                                // This is a new line
            Disconnect();
        Session.Disconnect(e.Message);                       // This is also a new line
    }
    return false;
}
@fernandozago
Copy link

Thank you. Fixed my problem.

My company have a lot of network issues... some of them is losing connectivity (and disconnecting without logout)

Would be nice to have this in the next version.

@gbirchmeier
Copy link
Member

Why not submit this as a PR?

Do you think you could devise a unit test to demonstrate the issue?

@VAllens
Copy link
Contributor

VAllens commented Mar 6, 2025

After I recently updated the version to 1.13.0, I have occasionally had this problem in a test environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants