From 9a61c79c29ba14f960f3df79134fc4e4e6c7daa6 Mon Sep 17 00:00:00 2001 From: "bodong.yang" Date: Thu, 5 Dec 2024 06:34:09 +0000 Subject: [PATCH] limit the failure_traceback field's length --- src/otaclient/_status_monitor.py | 7 +++++++ src/otaclient/main.py | 2 ++ src/otaclient/ota_core.py | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/otaclient/_status_monitor.py b/src/otaclient/_status_monitor.py index 02a6d2554..9d85972ef 100644 --- a/src/otaclient/_status_monitor.py +++ b/src/otaclient/_status_monitor.py @@ -251,7 +251,9 @@ def __init__( *, min_collect_interval: float = MIN_COLLECT_INTERVAL, shm_push_interval: float = SHM_PUSH_INTERVAL, + max_traceback_size: int, ) -> None: + self.max_traceback_size = max_traceback_size self.min_collect_interval = min_collect_interval self.shm_push_interval = shm_push_interval @@ -277,6 +279,11 @@ def load_report(self, report: StatusReport) -> bool: # ------ on session start/end ------ # if isinstance(payload, OTAStatusChangeReport): + if (_traceback := payload.failure_traceback) and len( + _traceback + ) > self.max_traceback_size: + payload.failure_traceback = _traceback[-self.max_traceback_size :] + new_ota_status = payload.new_ota_status if new_ota_status in [OTAStatus.UPDATING, OTAStatus.ROLLBACKING]: status_storage.session_id = report.session_id diff --git a/src/otaclient/main.py b/src/otaclient/main.py index 8b3f46036..ead66d666 100644 --- a/src/otaclient/main.py +++ b/src/otaclient/main.py @@ -39,6 +39,7 @@ SHUTDOWN_AFTER_API_SERVER_EXIT = 3 # seconds STATUS_SHM_SIZE = 4096 # bytes +MAX_TRACEBACK_SIZE = 2048 # bytes SHM_HMAC_KEY_LEN = 64 # bytes _ota_core_p: mp_ctx.SpawnProcess | None = None @@ -121,6 +122,7 @@ def main() -> None: ecu_status_flags=ecu_status_flags, op_queue=local_otaclient_op_queue, resp_queue=local_otaclient_resp_queue, + max_traceback_size=MAX_TRACEBACK_SIZE, ), name="otaclient_ota_core", ) diff --git a/src/otaclient/ota_core.py b/src/otaclient/ota_core.py index fb0bdabb3..b2e9b56e2 100644 --- a/src/otaclient/ota_core.py +++ b/src/otaclient/ota_core.py @@ -901,6 +901,7 @@ def ota_core_process( ecu_status_flags: MultipleECUStatusFlags, op_queue: mp_queue.Queue[IPCRequest], resp_queue: mp_queue.Queue[IPCResponse], + max_traceback_size: int, # in bytes ): from otaclient._logging import configure_logging from otaclient.configs.cfg import proxy_info @@ -915,6 +916,7 @@ def ota_core_process( _status_monitor = OTAClientStatusCollector( msg_queue=_local_status_report_queue, shm_status=shm_writer, + max_traceback_size=max_traceback_size, ) _status_monitor.start()