Skip to content

Commit 24c0ffc

Browse files
committed
Close connection on no/erroneous message received
Always close connection on no response/error response from modbus unit. This attempts to resolve issue #538, where the response of a previously timed out request over synchronized TCP is being returned as the response to the current request, by leaving the connection open only if there is no unanswered response. This commit only touches the code for synchronized clients, and only seeks to resolve it for TCP based clients, though the situation for UDP clients should improve as well.
1 parent 870be43 commit 24c0ffc

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pymodbus/transaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def execute(self, request):
200200
"/Unable to decode response")
201201
response = ModbusIOException(last_exception,
202202
request.function_code)
203+
self.client.close()
203204
if hasattr(self.client, "state"):
204205
_logger.debug("Changing transaction state from "
205206
"'PROCESSING REPLY' to "
@@ -209,6 +210,7 @@ def execute(self, request):
209210
return response
210211
except ModbusIOException as ex:
211212
# Handle decode errors in processIncomingPacket method
213+
self.client.close()
212214
_logger.exception(ex)
213215
self.client.state = ModbusTransactionState.TRANSACTION_COMPLETE
214216
return ex

0 commit comments

Comments
 (0)