Skip to content

Commit b294096

Browse files
server/asyncio.py change in the _log_exception method to correct the logging when disconnecting the socket (#1135)
removes undue reported error when forwarding this removes the error, when running a TCP server forwarding a serial server : ``` 17:10:21 ERROR mixin:113 Please do not use unit=, convert to slave=. ````
1 parent da82888 commit b294096

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pymodbus/server/async_io.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def _log_exception(self):
102102
"""Show log exception."""
103103
if isinstance(self, ModbusConnectedRequestHandler):
104104
txt = f"Handler for stream [{self.client_address[:2]}] has been canceled"
105-
_logger.error(txt)
105+
_logger.debug(txt)
106106
elif isinstance(self, ModbusSingleRequestHandler):
107-
_logger.error("Handler for serial port has been cancelled")
107+
_logger.debug("Handler for serial port has been cancelled")
108108
else:
109109
if hasattr(self, "protocol"):
110110
sock_name = (
@@ -113,7 +113,7 @@ def _log_exception(self):
113113
else:
114114
sock_name = "No socket"
115115
txt = f"Handler for UDP socket [{sock_name[1]}] has been canceled"
116-
_logger.error(txt)
116+
_logger.debug(txt)
117117

118118
def connection_made(self, transport):
119119
"""Call for socket establish
@@ -236,8 +236,9 @@ async def handle(self): # pylint: disable=too-complex
236236

237237
except asyncio.CancelledError:
238238
# catch and ignore cancellation errors
239-
self._log_exception()
240-
self.running = False
239+
if self.running:
240+
self._log_exception()
241+
self.running = False
241242
except Exception as exc: # pylint: disable=broad-except
242243
# force TCP socket termination as processIncomingPacket
243244
# should handle application layer errors

0 commit comments

Comments
 (0)