From 389d205fbc106f6cdb674cfd08b1675e5355d5e0 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Wed, 16 Jul 2025 17:10:15 +0200 Subject: [PATCH 1/3] avoids earli garbage collection --- .../modules/outputs/_manager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py index 367d5dc224a8..0063597ab270 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py @@ -148,6 +148,9 @@ async def _upload_ports() -> None: task_name = f"outputs_manager_port_keys-{'_'.join(port_keys)}" self._task_uploading = create_task(_upload_ports(), name=task_name) + # used to retain task to avoid early garabage collection + cleanup_task: Task | None = None + def _remove_downloads(future: Future) -> None: # pylint: disable=protected-access if future._exception is not None: @@ -171,7 +174,8 @@ def _remove_downloads(future: Future) -> None: except Exception as e: # pylint: disable=broad-except self._last_upload_error_tracker[port_key] = e - create_task(self._port_key_tracker.remove_all_uploading()) + nonlocal cleanup_task + cleanup_task = create_task(self._port_key_tracker.remove_all_uploading()) self._task_uploading.add_done_callback(_remove_downloads) From d82911075a5b31cb9c29ee02e5b00de676aaaf9a Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Thu, 17 Jul 2025 10:08:18 +0200 Subject: [PATCH 2/3] retain task and properly cancel --- .../modules/outputs/_manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py index 0063597ab270..acf1f4a09d38 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py @@ -118,6 +118,7 @@ def __init__( self._port_key_tracker = _PortKeyTracker() self._task_uploading: Task | None = None + self._task_uploading_followup: Task | None = None self._task_scheduler_worker: Task | None = None self._schedule_all_ports_for_upload: bool = False @@ -148,9 +149,6 @@ async def _upload_ports() -> None: task_name = f"outputs_manager_port_keys-{'_'.join(port_keys)}" self._task_uploading = create_task(_upload_ports(), name=task_name) - # used to retain task to avoid early garabage collection - cleanup_task: Task | None = None - def _remove_downloads(future: Future) -> None: # pylint: disable=protected-access if future._exception is not None: @@ -174,8 +172,9 @@ def _remove_downloads(future: Future) -> None: except Exception as e: # pylint: disable=broad-except self._last_upload_error_tracker[port_key] = e - nonlocal cleanup_task - cleanup_task = create_task(self._port_key_tracker.remove_all_uploading()) + self._task_uploading_followup = create_task( + self._port_key_tracker.remove_all_uploading() + ) self._task_uploading.add_done_callback(_remove_downloads) @@ -183,6 +182,10 @@ async def _uploading_task_cancel(self) -> None: if self._task_uploading is not None: await _cancel_task(self._task_uploading, self.task_cancellation_timeout_s) await self._port_key_tracker.move_all_uploading_to_pending() + if self._task_uploading_followup is not None: + await _cancel_task( + self._task_uploading_followup, self.task_cancellation_timeout_s + ) async def _scheduler_worker(self) -> None: if await self._port_key_tracker.are_pending_ports_uploading(): From 398d498cf17906f2bf1c7b8cbb91aaf87a458859 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Thu, 17 Jul 2025 10:12:00 +0200 Subject: [PATCH 3/3] copilot --- .../simcore_service_dynamic_sidecar/modules/outputs/_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py index acf1f4a09d38..a58216b34861 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/outputs/_manager.py @@ -182,10 +182,12 @@ async def _uploading_task_cancel(self) -> None: if self._task_uploading is not None: await _cancel_task(self._task_uploading, self.task_cancellation_timeout_s) await self._port_key_tracker.move_all_uploading_to_pending() + self._task_uploading = None if self._task_uploading_followup is not None: await _cancel_task( self._task_uploading_followup, self.task_cancellation_timeout_s ) + self._task_uploading_followup = None async def _scheduler_worker(self) -> None: if await self._port_key_tracker.are_pending_ports_uploading():