Skip to content

Remove unnecessary IoSession.close() for session that is already closed#1056

Merged
chrjohn merged 1 commit into
quickfix-j:masterfrom
the-thing:remove-closed
Oct 4, 2025
Merged

Remove unnecessary IoSession.close() for session that is already closed#1056
chrjohn merged 1 commit into
quickfix-j:masterfrom
the-thing:remove-closed

Conversation

@the-thing

@the-thing the-thing commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

Close is definitely not required here. At this stage the session is already closed. Close is idempotent so it has no effect.

Call stack.

  • quickfix.mina.AbstractIoHandler#sessionClosed
  • quickfix.mina.initiator.InitiatorProxyIoHandler#sessionClosed
  • org.apache.mina.core.filterchain.DefaultIoFilterChain.TailFilter#sessionClosed

I created additional logging on a different branch to make sure that org.apache.mina.core.session.IoSession#isClosing is true every time we get here.

@Override
public void sessionClosed(IoSession ioSession) {
    try {
        Session quickFixSession = findQFSession(ioSession);
        if (quickFixSession != null) {
            eventHandlingStrategy.onMessage(quickFixSession, EventHandlingStrategy.END_OF_STREAM);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        Object oldAttribute = ioSession.removeAttribute(SessionConnector.QF_SESSION);
        log.info("test_close [closing={},oldAttribute={}]", ioSession.isClosing(), oldAttribute);
        ioSession.closeOnFlush();
    }
}

See build logs in my fork - https://github.com/the-thing/quickfixj/actions/runs/18196717686

Also code https://github.com/apache/mina/blob/04a9b94a3705728f0c805444bf0d54d770fa4b47/mina-core/src/main/java/org/apache/mina/core/session/AbstractIoSession.java#L332

@chrjohn

chrjohn commented Oct 3, 2025

Copy link
Copy Markdown
Member

Is this related to #928 ? But probably just coincidence.

@the-thing

Copy link
Copy Markdown
Contributor Author

Related in the sense that I found while looking at it. It will not fix anything except one less unnecessary line of code.

@chrjohn chrjohn changed the title Remove unnecessary session close for session that is already closed Remove unnecessary IoSession.close() for session that is already closed Oct 4, 2025
@chrjohn chrjohn merged commit 5db3e69 into quickfix-j:master Oct 4, 2025
12 checks passed
@chrjohn chrjohn added this to the QFJ 3.0.0 milestone Oct 4, 2025
@the-thing the-thing deleted the remove-closed branch October 4, 2025 15:54
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

Successfully merging this pull request may close these issues.

2 participants