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
QFJ-885 Send logout message before stopping initiators #101
QFJ-885 Send logout message before stopping initiators #101
Conversation
Because logout sets a flag indicating we should logout, we rely on another thread to send the logout message. If we stop the initiators first that doesn't happen. See JIRA: (QFJ-885)[http://www.quickfixj.org/jira/browse/QFJ-885]
logoutAllSessions(forceDisconnect); | ||
stopSessionTimer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably superfluous, since stopInitiators()
will call this anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, call to stopSessionTimer() has been removed in 5f36509
And stopInitiators() was also added in that commit, but it seems it would have been better to move it below the logoutAllSessions() call.
logoutAllSessions(forceDisconnect); | ||
stopSessionTimer(); | ||
if (!forceDisconnect) { | ||
waitForLogout(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't required because logoutAllSessions(forceDisconnect)
does exactly the same, unless the sessions weren't initialised... in which case any point waiting for logout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it is not necessary.
Hi @alphafoobar |
Hi @chrjohn |
Hi @alphafoobar , regarding the unit test: I checked it and there was no existing test failing but one that I wrote to check for the correct behaviour. But I did not get around to correct the problem due to time constraints. However, there have to be more changes to correct the problem since you were only changing the ThreadedSocketInitiator. But the problems were reported against the default SocketInitiator. Thanks, |
Hi @chrjohn, Thanks for checking, we only use the Cheers |
This allows the logout message to be generated and sent. Otherwise `stopHandlingMessages` enqueues the `END_OF_STREAM` message. See JIRA: (QFJ-885)[http://www.quickfixj.org/jira/browse/QFJ-885]
Incorporating peer review feedback.
These comments are specifically related to the test > SingleThreadedEventHandlingStrategyTest.shouldCleanUpInitiatorQFJMessageProcessorThreadAfterStop:248 : TestTimedOut The call to stopHandlingMessages should happen after calling logout. Otherwise a logout message won't be sent. ```java logoutAllSessions(forceDisconnect); stopInitiators(); eventHandlingStrategy.stopHandlingMessages(); ``` Assuming sessions have connected, this refactor is fine. When sessions do not connect as per this test, the `initialize` method (which ends up waiting for a connection) blocks the eventual call to `stop`, since both are mostly guarded by `this`.
Since it would require further refactoring of the SocketInitiator.
Hi @chrjohn I have added some unit testing that shows a logout is happening, I was able to add those tests onto an unpatched branch and show that a logout was not sent. I also looked at adding this for the Thanks, |
Thanks @alphafoobar , I will take a look shortly. |
This reverts commit 39492ff.
Without posting the END_OF_STREAM message which is responsible for disconnecting the session connector and prevent the processing of the LOGOUT message and any others that might be queued. JIRA: QFJ-885
259507f
to
7ce6b02
Compare
Following the same approach as the SocketInitiator. JIRA: QFJ-885
15d087b
to
439c21d
Compare
Hi @alphafoobar, does your build run successfully with this changes? I have several unit test failures, e.g. in SocketInitiatorTest.testDoubleStartOfInitiator. |
Hi @chrjohn, Sorry about that, I am seeing that unit test fail. I'll look into why that's happening. Cheers, |
This change pulls the stopHandlingMessages method out of the synchronized block. Using the stop first pattern seems to let the Acceptor's QFJ Message Processing thread to linger. JIRA: QFJ-885
JIRA: QFJ-885
Hi @chrjohn, With the changes in this PR, the Sending the Since the acceptor change is breaking tests I've backed it out. Cheers, |
Hi @alphafoobar , thanks for your input. I am thinking about relaxing the synchronization around the What do you think? |
Hi @chrjohn It sounds sensible, starting and stopping the initiator/acceptors are activities that are unlikely to see much contention and the I've been thinking that it would make more sense for the blocking thread to add the END_OF_STREAM message on the end of the queue once it realises it has been stopped, for example in if (!eventQueue.isEmpty()) {
final List<SessionMessageEvent> tempList = new ArrayList<>();
eventQueue.drainTo(tempList);
for (SessionMessageEvent event : tempList) {
event.processMessage();
}
for (Session quickfixSession : sessionConnector.getManagedSessions()) {
new SessionMessageEvent(quickfixSession, END_OF_STREAM).processMessage();
}
} I'm happy to help, |
Hi @alphafoobar , |
Hi Chris, sounds good. Cheers! |
Hi @alphafoobar, |
QFJ-885 Logout message is not sent out - based on #101 by @alphafoobar
QFJ-885 Logout message is not sent out - based on #101 by @alphafoobar (cherry picked from commit 916f260)
Cool, thanks @chrjohn ! |
Because logout sets a flag indicating we should logout, we rely on another thread to send the logout message.
If we stop the initiators first that doesn't happen.
See JIRA: (QFJ-885)[http://www.quickfixj.org/jira/browse/QFJ-885]