secsgem icon indicating copy to clipboard operation
secsgem copied to clipboard

communication state is not updated after broken TCP/IP connection

Open manuelarink opened this issue 2 months ago • 0 comments

Hi Benjamin,

thanks a lot for your great work on this library!

When working with version 0.3.0 professionally I came across an issue when the Tcp/Ip connection to an equipment breaks off while our handlers are running. In this case an exception is thrown and the connection state is correctly updated to "NOT_CONNECTED", while the communication state is not updated at all. As our implementations of GemHostHandler expect a change in communication state (from "COMMUNICATING" to "NOT_COMMUNICATING") and this doesn't happen, we didn't notice the disconnection.

I worked around this bug (?) with listening to the "disconnected" event fired in the _on_disconnected function of HSMSProtocol additionally to the change in communication state, but I think this is not a good solution. I suggest that the transition "communicationfail" of CommunicationStateMachine should be triggered by the lib in case of unexpected disconnection. Currently I'm trying to fix this issue in a fork of the version 0.3.0 branch and added the following line of code to the constructor of class GemHandler

    `self._protocol.events.disconnected += self.on_connection_closed`

as this triggers the transition "communicationfail" of communication state. But this is not a good solution too, because in case of regular shutdown disable() and on_connection_closed() of GemHandler are both executed.

Maybe you can have a look at this problem and provide a solution.

Regards, Manuela

manuelarink avatar Dec 03 '24 09:12 manuelarink