Skip to content

System not trying second address #1260

Open

Description

@morvael

Describe the bug
I have a system configured with 2 addresses. If the first one is not responding during launch of application it will not try second system and will eventually quit (because the init code waits up to 60 seconds for successful login or other meaningful response).

Expected behavior
System tries second address in 30 seconds.

system information:

  • OS: Linux
  • Java version: JDK21
  • QFJ Version: 3.0.1

Additional context

20260613-12:20:11: Session FIXT.1.1:xxx->yyy schedule is daily, 05:30:00-UTC - 17:30:00-UTC (daily, 07:30:00-CEST - 19:30:00-CEST)
20260613-12:20:11: Created session: FIXT.1.1:xxx->yyy
20260613-12:20:11: Configured socket addresses for session: [/127.0.0.1:10134, /127.0.0.1:10135]
20260613-12:20:11: MINA session created: local=/127.0.0.1:43448, class org.apache.mina.transport.socket.nio.NioSocketSession, remote=view-localhost/127.0.0.1:10134
20260613-12:20:11: Disconnecting: Encountered END_OF_STREAM
20260613-12:20:41: MINA session created: local=/127.0.0.1:56316, class org.apache.mina.transport.socket.nio.NioSocketSession, remote=view-localhost/127.0.0.1:10134
20260613-12:20:41: Disconnecting: Encountered END_OF_STREAM

I think it may be caused by no callbacks reaching me because Session.next has this code:

if (message == EventHandlingStrategy.END_OF_STREAM) {
  disconnect(ENCOUNTERED_END_OF_STREAM, false);
  return;
}

and disconnect has this code:

if (logonReceived || logonSent) {
  try {
    application.onLogout(sessionID);

so I'm never notified of this. But that doesn't explain why it only tries the first socket address again and again.

Activity

  1. added theissue type on Jun 13, 2026
  2. morvael commented on Jun 13, 2026

    @morvael
    Author

    Maybe the problem is with IoSessionInitiator.pollConnectFuture() which always resets nextSocketAddressIndex to 0? But this is just my wild guess.

  3. morvael commented on Jun 13, 2026

    @morvael
    Author

    This is the stacktrace where it set nextSocketAddressIndex from 1 to 0 and attempted to reconnect to the same bad address:

    edit: sorry uploading images failed so here's link: https://ibb.co/VW2DLFBX

  4. chrjohn commented on Jun 13, 2026

    @chrjohn
    Member

    I need to look at this after the weekend. Setting SocketConnectTimeout should help with the long delay though

  5. morvael commented on Jun 13, 2026

    @morvael
    Author

    Disconnect is immediate, but there's no callback about this and in 30 seconds there's the next connection attempt, sadly again to first address. I think this is some special disconnect, maybe FW Reject. It's part of disaster recovery tests.

  6. chrjohn commented on Jun 13, 2026

    @chrjohn
    Member

    there's no callback about this

    StateListener.onDisconnect() should get called. Maybe also .onConnectException(), but probably not since I cannot see any exception in the log.

  7. the-thing commented on Jun 14, 2026

    @the-thing
    Collaborator

    @chrjohn How similar is this to #402? I think the underlaying cause might the same or just the same failure.

    The author of the other issue claims that the failover mechanism works for unresolved address which makes sense since quickfix.mina.initiator.IoSessionInitiator.ConnectTask#getNextSocketAddress could throw an IllegalArgumentException when hostname is null from the previous, unresolved attempt. This will skip quickfix.mina.initiator.IoSessionInitiator.ConnectTask#pollConnectFuture call.

    morvael might be onto something here.

  8. chrjohn commented on Jun 16, 2026

    @chrjohn
    Member

    @the-thing looks like a similar issue to me. Any idea how we could detect the timeout?

  9. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    I will have a look soon, but it seems like there are two things that we have to confirm.

    • quickfix.SessionStateListener#onDisconnect is getting called (I think it does)
    • check round robin for multiple addresses
  10. morvael commented on Jun 17, 2026

    @morvael
    Author

    I admit I'm maybe not using SessionStateListener, so only the round robin thing is a problem.

  11. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    @the-thing looks like a similar issue to me. Any idea how we could detect the timeout?

    I think the timeout is already being detected.

  12. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    This is probably the breaking change.

    #152

  13. morvael commented on Jun 17, 2026

    @morvael
    Author

    Yeah, I do a full recycle of the client between days so they would already start from host 0. However my scenario is that it restarts from 0 in one lifecycle without any other commands. These two states should be somehow distinguished.

  14. morvael commented on Jun 17, 2026

    @morvael
    Author

    I guess some kind of alternative would be to create client with just one host and on specific events change the host in the configuration (rebuilding the client if that's required), but this seems too heavy. Maybe add a config switch allowing/disallowing this kind of round robin ignoring?

  15. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    I guess some kind of alternative would be to create client with just one host and on specific events change the host in the configuration (rebuilding the client if that's required), but this seems too heavy. Maybe add a config switch allowing/disallowing this kind of round robin ignoring?

    Config is probably not the best, because we will have 2 broken functionalities driven by a configuration.

    @chrjohn @morvael

    We could write custom round robin mechanics, but this requires a bit of thinking and some changes to get it right so I would avoid it for the time being. Here is what I'm thinking.

    Currently we use different String resasons for disconnect reasons. Add an additional flag indicating if session was disconnected by END_OF_STREAM (initially boolean, maybe enum later for more reasons if required). The flag is stored in the quickfix.Session state. When new connection is made we check the flag and decide when the index should advance and / or be reset.

    The implication of this is that if a session failovers during the day to Host2 and then sessions is disconnect by EndTime and later connected again it will still connect to Host2, but I guess this is expected behavior...

  16. morvael commented on Jun 17, 2026

    @morvael
    Author

    It's not that round robin doesn't advance. It does advance but is later reset on reconnect, treated as fresh. Can manual connect be the only one resetting round robin index and the one called from repeat timer don't?

  17. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    That's what I meant. I rephrased.

  18. the-thing commented on Jun 17, 2026

    @the-thing
    Collaborator

    @chrjohn

    Let me know how you want to approach this. I can probably prototype something soon.

    One thing to highlight is what morvael said and how it looks in the code is that connection attempts are made sequentially from host 1..n. When successful connection is made to any HostX, where 1<= x <= n, the next connect attempt will again start from Host1. This seems to be the current logic.

    If we start fiddling this is going to change. This is also what blocks failover in #402. Looking at the log it seems that connection is made (MINA) + fix handshake. It will never failover in this case, because on successful connect resets the Host to 1.

  19. chrjohn commented on Jun 18, 2026

    @chrjohn
    Member

    @the-thing

    Looking at the log it seems that connection is made (MINA) + fix handshake

    As written in #402 , to me a successful FIX connection is the exchange of Logon messages, i.e. Logon sent and received. Otherwise it is no successful FIX connection.

    I mentioned somewhere else that we should probably have some kind of interface/strategy if someone would like to tweak the failover behaviour. But maybe it is sufficient to change the logic to not treat a successful TCP connection as if it was a working FIX connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions