TimelordUK / jspurefix

native typescript FIX engine
MIT License
58 stars 27 forks source link

Fix initiator cleanup if the session is terminated unexpectedly #18

Closed NiklasZ closed 3 years ago

NiklasZ commented 3 years ago

Hi there,

A while ago I ran into a bug where the acceptor stopped sending heartbeats and my jspurefix initiator's Promise was rejected, triggering the shutdown of the service.

  try {
    await initiator(fixConfig, () => adapter);
  } catch (e: any) {
    logger.error(`Adapter failed with ${e.message}`);
  } finally {
    await shutdown();
  }

But then the transport kept running (the log is in newest-first order), which I'm guessing is not intended behaviour.

"2021-04-23T23:55:55.112Z [Acceptor-Name UAT client:FixSession] info: reset from previous transport.\n"
"2021-04-23T23:55:55.111Z [initiator] info: ... connected, run session\n"
"2021-04-23T23:55:55.109Z [Acceptor-Name UAT client:TcpInitiator] info: net.createConnection cb, resolving\n"
{
  "msg": "Shutting down...",
  "name": "@our-company/fix-adapter"
}
{
  "name": "@our-company/fix-adapter",
  "msg": "Adapter failed with Acceptor-Name UAT client: peer not responding"
}

anonymised.log

This PR should fix the issue :smiley: