Bugs5382 / node-hl7-client

A pure Node.js HL7 Client that allows for communication to a HL7 Broker/Server that can send properly formatted HL7 messages with ease.It can also parse and then you can extract message segments out.
MIT License
14 stars 4 forks source link

fix(#100): Ensure correct connection closure #112

Closed seanjb closed 2 months ago

seanjb commented 2 months ago

The connection closure method sets the readyState to CLOSING and emits a close event to the socket, then sets the ready state to CLOSED.

However, due to a race condition, the readyState is already at the state of CLOSED when the socket close method is triggered. This causes an exception and a reconnection attempt. As reported in #100

This fix ensures the connectionTimer is cleared before emitting the close event, and updates the socket close handler to only throw an exception if the closure was unexpected (e.g. readyState is not CLOSED and the connectionTimer was not previously destroyed).

Tests added to ensure the new logic is closing the connection correctly. Removing the changes to the connection.ts method the tests correctly catch the closure exception and fail.

Bugs5382 commented 2 months ago

:tada: This PR is included in version 2.3.1-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Bugs5382 commented 2 months ago

:tada: This PR is included in version 2.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: