From 598599c0d2448391a0cec6ca03c00a76650a063e Mon Sep 17 00:00:00 2001 From: Carlos Chinchilla Date: Thu, 27 Jul 2023 01:21:04 +0000 Subject: pw_{console,hdlc}: Detect comms errors in Python - Log raised exceptions when reading a communication transport. - Detect socket disconnects when reading or writing. - Make console try to reconnect on socket disconnect events. Change-Id: I2e87390d1d340c31e2963936c76d91f08e3baecd Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/155814 Pigweed-Auto-Submit: Carlos Chinchilla Reviewed-by: Taylor Cramer Commit-Queue: Auto-Submit --- pw_hdlc/py/pw_hdlc/rpc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'pw_hdlc/py') diff --git a/pw_hdlc/py/pw_hdlc/rpc.py b/pw_hdlc/py/pw_hdlc/rpc.py index b1998830e..64bca2051 100644 --- a/pw_hdlc/py/pw_hdlc/rpc.py +++ b/pw_hdlc/py/pw_hdlc/rpc.py @@ -280,8 +280,12 @@ class HdlcRpcClient(RpcClient): _LOG.exception('Exception in HDLC frame handler thread') decoder = FrameDecoder() + + def on_read_error(exc: Exception) -> None: + _LOG.error(str(exc)) + reader = DataReaderAndExecutor( - read, lambda exc: None, decoder.process_valid_frames, handle_frame + read, on_read_error, decoder.process_valid_frames, handle_frame ) super().__init__(reader, paths_or_modules, channels, client_impl) @@ -312,8 +316,11 @@ class NoEncodingSingleChannelRpcClient(RpcClient): def process_data(data: bytes): yield data + def on_read_error(exc: Exception) -> None: + _LOG.error(str(exc)) + reader = DataReaderAndExecutor( - read, lambda exc: None, process_data, self.handle_rpc_packet + read, on_read_error, process_data, self.handle_rpc_packet ) super().__init__(reader, paths_or_modules, [channel], client_impl) -- cgit v1.2.3