quickfixj icon indicating copy to clipboard operation
quickfixj copied to clipboard

System doesn't break TCP/IP connection when sending Logon message with ResetSeqNumFlag (141)=Y and Invalid MsgSeqNum (!=1)

Open harinda05 opened this issue 3 years ago • 6 comments

Describe the bug We’ve developed a fix trading gateway using quickfixj library.

When a user sends a Logon message to the system for a user, with ResetSeqNumFlag = Y and MsgSeqNum !=1 we expect the system to break the TCP/IP connection after sending a Logout message due to the MsgSeqNum being invalid.

To Reproduce Step to reproduce:

  1. Establish TCP/IP connection
  2. Send Logon message to the system with SenderCompID of active user
  3. Receive Logon message from the system
  4. Receive Heartbeat message
  5. Send Heartbeat message
  6. Send Logout message
  7. Receive Logout message
  8. Send Logon message to the system with SenderCompID of active user and ResetSeqNumFlag = Y and MsgSeqNum !=1
  9. Receive Logout message

Expected behavior

  • Expected behavior: logout message from the system since MsgSeqNum != 1

Actual behavior: System isn’t sending logout. Instead sends a logon response.

system information:

  • OS: [e.g. Linux]
  • Java version [e.g. JDK11]
  • QFJ Version [e.g. 2.0.3]

harinda05 avatar Apr 22 '22 07:04 harinda05

Wow, I had to do some FIX spec digging to find out if this really is a bug. At the moment I am not sure since I didn't find something that applies to this situatuon. Can you present some excerpt from the FIX spec that says that this really is a bug? Thanks, Chris.

chrjohn avatar Apr 26 '22 09:04 chrjohn

According to FIX_Session_Layer_with_Errata_November_2020.pdf Section 5.4.7

5.4.7 Validation of message sequence numbers
If a received message has a MsgSeqNum(34) less than NextNumIn, a serious error exists. The FIX session and transport
layer connection should be terminated unless the message received is:

• a SequenceReset(35=4) message with PossDupFlag(43) present with a value of “Y”.
• any message of a message type that supports retransmission with a PossDupFlag(43) present with a value
of “Y”.
• a Logon(35=A) message with ResetSeqNumFlag(141) present with a value of “Y”.

_**If a received message has a MsgSeqNum(34) greater than NextNumIn, a serious error exists. The FIX session and
transport layer connection should be terminated.**_

With regards to the mentioned scenario the connection should be terminated in scenarios MsgSeqNumber is greater than the expected MsgSeqNumber

Many thanks, Harinda

harinda05 avatar May 13 '22 07:05 harinda05

Hmm, that is actually the description from the LFIXT session profile.

The Lightweight FIXT session profile (LFIXT) is a restriction of the FIXT session profile. LFIXT eliminates the use of session layer retransmission of messages to simplify the session layer protocol.

So not actually what QFJ is implementing by default. I will check whether I find something useful in the FIX protocol forum and report back.

BTW, your initial request was about sequence number being different than 1, the excerpt from the spec above talks about the sequence number being greater than the next expected seqnum.

chrjohn avatar May 16 '22 15:05 chrjohn

BTW, your initial request was about sequence number being different than 1, the excerpt from the spec above talks about the sequence number being greater than the next expected seqnum.

Yes, in this scenario the expected seqNum is 1. You are correct , it should be changed to being greater than the seqNum 1.

So not actually what QFJ is implementing by default. I will check whether I find something useful in the FIX protocol forum and report back.

Many thanks

harinda05 avatar May 17 '22 04:05 harinda05

Another question @harinda05

Actual behavior: System isn’t sending logout. Instead sends a logon response.

But it does reset the sequence number and the session is up and running after this?

Edit: I have created a forum post: https://forum.fixtrading.org/t/sequence-number-on-logon-message-when-resetseqnumflag-y/16562

While writing it it occurred to me that maybe you are confusing two scenarios: https://www.fixtrading.org/standards/fix-session-layer-online/#using-resetseqnumflag141-to-reset-fix-session-for-24-hour-connectivity and https://www.fixtrading.org/standards/fix-session-layer-online/#using-resetseqnumflag141-to-reset-fix-session-during-fix-connection-establishmentresetseqnumflag

Your case seems to be the latter (since the seqnum is reset after disconnection) but there is no mentioning that the sequence number has to be 1.

chrjohn avatar May 17 '22 14:05 chrjohn

But it does reset the sequence number and the session is up and running after this? Yes this is correct.

Edit: I have created a forum post: https://forum.fixtrading.org/t/sequence-number-on-logon-message-when-resetseqnumflag-y/16562

Thanks for opening thread.

While writing it it occurred to me that maybe you are confusing two scenarios:
https://www.fixtrading.org/standards/fix-session-layer-online/#using-resetseqnumflag141-to-reset-fix-session-for-24-hour-connectivity and https://www.fixtrading.org/standards/fix-session-layer-online/#using-resetseqnumflag141-to-reset-fix-session-during-fix-connection-establishmentresetseqnumflag

Thanks for pointing this out. I will follow up on this as well.

harinda05 avatar May 19 '22 05:05 harinda05

In my opinion it does not make sense to impose restrictions on the sequence number of the Logon message when the intention is to reset the sequence numbers anyway. This is followed in #549 as well. I will close this issue for now. Please reopen if you have any new information.

chrjohn avatar Oct 07 '22 09:10 chrjohn