Skip to content

Commit

Permalink
limit the failure_traceback field's length
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 5, 2024
1 parent d85823f commit 9a61c79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/otaclient/_status_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/otaclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
)
Expand Down
2 changes: 2 additions & 0 deletions src/otaclient/ota_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit 9a61c79

Please sign in to comment.