From 5690c728fa1aab9acf97ade2c6836418e93b574d Mon Sep 17 00:00:00 2001 From: dhoomakethu Date: Thu, 11 Mar 2021 20:33:05 +0530 Subject: [PATCH 1/2] Fix/Workaround for #612, #614 , avoid disconnects on succesful reads --- CHANGELOG.rst | 1 + pymodbus/transaction.py | 4 +++- pymodbus/version.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9e93d58ba..4b4d2caad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,7 @@ version 2.5.1 * Bug fix TCP Repl server. * Support multiple UID's with REPL server. * Support serial for URL (sync serial client) +* Bug fix/enhancements, close socket connections only on empty or invalid response version 2.5.0 ---------------------------------------------------------- diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index 38169a829..d07983a98 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -217,19 +217,21 @@ def execute(self, request): "/Unable to decode response") response = ModbusIOException(last_exception, request.function_code) + self.client.close() if hasattr(self.client, "state"): _logger.debug("Changing transaction state from " "'PROCESSING REPLY' to " "'TRANSACTION_COMPLETE'") self.client.state = ( ModbusTransactionState.TRANSACTION_COMPLETE) - self.client.close() + return response except ModbusIOException as ex: # Handle decode errors in processIncomingPacket method _logger.exception(ex) self.client.close() self.client.state = ModbusTransactionState.TRANSACTION_COMPLETE + self.client.close() return ex def _retry_transaction(self, retries, reason, diff --git a/pymodbus/version.py b/pymodbus/version.py index 1e556a81d..a667c28e7 100644 --- a/pymodbus/version.py +++ b/pymodbus/version.py @@ -41,7 +41,7 @@ def __str__(self): return '[%s, version %s]' % (self.package, self.short()) -version = Version('pymodbus', 2, 5, 1) +version = Version('pymodbus', 2, 5, 1, "rc1") version.__name__ = 'pymodbus' # fix epydoc error From c7a582b6796be211d693dba80367f2b26846c134 Mon Sep 17 00:00:00 2001 From: dhoomakethu Date: Thu, 1 Apr 2021 11:25:28 +0530 Subject: [PATCH 2/2] remove duplicate client close calls --- pymodbus/transaction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index d07983a98..96d54d7c2 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -229,7 +229,6 @@ def execute(self, request): except ModbusIOException as ex: # Handle decode errors in processIncomingPacket method _logger.exception(ex) - self.client.close() self.client.state = ModbusTransactionState.TRANSACTION_COMPLETE self.client.close() return ex