Logout flow handled incorrectly (it generates a loop)
When a counterparty starts a logout flow, by sending a Logout message, it's supposed to respond with a Logout ACK (represented by the same message type). When the party that sent the original logout message receives the ACK, the connection is finished.
Right now, both Client and Server Session Message Processors use the same logout handler:
export const handleLogout = (parser: IFIXParser, message: Message): void => {
parser.isLoggedIn = false;
const logoutAcknowledge: Message = parser.createMessage(
...
);
parser.send(logoutAcknowledge);
log(`FIXServer (${parser.protocol!.toUpperCase()}): >> sent Logout acknowledge`);
parser.stopHeartbeat();
parser.close();
};
So, when any of them receives a Logout, it sends back the ACK, which generates a new ACK to be sent by the other part and a loop is started (it ends because the Server raises an error when it tries to send a message on a closed socket).
I don't have so much context on your implementation but I think that something like the following may fix the issue by preventing to close already closed sessions:
export const handleLogout = (parser: IFIXParser, message: Message): void => {
if(!parser.isLoggedIn) {
log(`FIXServer (${parser.protocol!.toUpperCase()}): Session already logged out (Logout acknowledge received)`);
return;
}
parser.isLoggedIn = false;
const logoutAcknowledge: Message = parser.createMessage(
...
);
parser.send(logoutAcknowledge);
log(`FIXServer (${parser.protocol!.toUpperCase()}): >> sent Logout acknowledge`);
parser.stopHeartbeat();
parser.close();
};