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

Use shutdown for socket on stop with handling ENOTCONN error #202

Closed
wants to merge 1 commit into from

Conversation

tyler92
Copy link

@tyler92 tyler92 commented May 23, 2023

MR #201 wasn't correct. Blocking recv is not interrupted by the close function, only shutdown can interrupt it.

Copy link
Member

@dakka dakka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide test cases. This won't be merged as is.

@tyler92
Copy link
Author

tyler92 commented May 23, 2023

I am not very familiar with the FIX8 library tests and would be grateful if you could tell me in which of the existing tests this can be added

@tyler92
Copy link
Author

tyler92 commented Jul 13, 2023

OK, I found a way how to reproduce it with f8test target.

  1. Change ignore_logon_sequence_check to false in test/myfix_server.xml
  2. Desynchronize sequence numbers for the server and the client. We have to get "Message Sequence too low" on the next step.
  3. Run the server .libs/f8test -sml server_log
  4. Run the client ./f8test -l client_log
  5. Observe the error in logs: Net Exception. In fact, it's Net Exception: Socket is not connected (ENOTCONN)

And it's a memory leak:

virtual ~SessionInstance ()
{
    try
    {
        if (_psc != nullptr)
        {
            _psc->stop();  // the exception is occurred here
            delete _psc;   // will never be freed
            _psc = nullptr;
        }
    }
...
    catch (Poco::Exception& e)
    {
        this->_session->log(e.what(), Logger::Error);
    }

@tyler92 tyler92 requested a review from dakka July 17, 2023 07:03
if (e.code() != ENOTCONN)
{
scout_debug << "rethrowing Poco::Exception: " << e.displayText();
throw;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, as you said on #201 an exception on stop will lead to termination due to an exception. You can't throw without changing more code.
Would need to change stop to take a bool can_throw = true, where on connection destructor we call it as stop(false) . Capture every exception log it and throw it only if we can.
Other issue not related to your commit is that in coro mode, _reader.started() is never true, meaning we will never shutdown the socket.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will close the MR, it seems nobody is interested in the patch

@tyler92 tyler92 closed this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants