From a1f35b5dfebc6319eeb5ceff9f7eedc70b0f0288 Mon Sep 17 00:00:00 2001 From: Avnithakur731-a Date: Sat, 30 May 2026 11:02:09 +0530 Subject: [PATCH 1/4] Fix race condition in task cancellation handling --- backend/secuscan/executor.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/backend/secuscan/executor.py b/backend/secuscan/executor.py index 01a68020..eab5f9f7 100644 --- a/backend/secuscan/executor.py +++ b/backend/secuscan/executor.py @@ -637,13 +637,7 @@ async def cancel_task(self, task_id: str) -> bool: logger.error(f"Failed to kill docker container for {task_id}: {e}") db = await get_db() - await db.execute( - "UPDATE tasks SET status = ?, completed_at = ? WHERE id = ?", - (TaskStatus.CANCELLED.value, datetime.now().isoformat(), task_id) - ) - - await self._broadcast(task_id, "status", TaskStatus.CANCELLED.value) - await self._invalidate_cached_views() + await db.log_audit( "task_cancelled", From cb23beba13a939e13c5a43899b51a83c54cda88f Mon Sep 17 00:00:00 2001 From: Avnithakur731-a Date: Sat, 30 May 2026 11:12:39 +0530 Subject: [PATCH 2/4] Fix formatting issue --- backend/secuscan/executor.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/secuscan/executor.py b/backend/secuscan/executor.py index eab5f9f7..48b0c2a2 100644 --- a/backend/secuscan/executor.py +++ b/backend/secuscan/executor.py @@ -638,7 +638,6 @@ async def cancel_task(self, task_id: str) -> bool: db = await get_db() - await db.log_audit( "task_cancelled", "Task cancelled by user", @@ -653,7 +652,7 @@ async def get_task_status(self, task_id: str) -> Optional[Dict]: task_row = await db.fetchone( """ SELECT id, plugin_id, tool_name, target, status, scan_phase, created_at, started_at, completed_at, - duration_seconds, exit_code, error_message, preset, inputs_json + duration_seconds, exit_code, error_message, preset, inputs_json FROM tasks WHERE id = ? """, (task_id,) @@ -822,7 +821,7 @@ async def _upsert_findings_and_report_from_scanner(self, db, task_id: str, scann exploitability, confidence, asset_exposure, risk_score, risk_factors_json ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?) + ?, ?, ?, ?, ?) """, ( finding_id, From c8eba00a64b44423bb60a5824a76dd22e7ff5b4a Mon Sep 17 00:00:00 2001 From: Avnithakur731-a Date: Sat, 30 May 2026 11:25:15 +0530 Subject: [PATCH 3/4] Remove trailing whitespace --- backend/secuscan/executor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/secuscan/executor.py b/backend/secuscan/executor.py index 48b0c2a2..7ed91e00 100644 --- a/backend/secuscan/executor.py +++ b/backend/secuscan/executor.py @@ -637,7 +637,6 @@ async def cancel_task(self, task_id: str) -> bool: logger.error(f"Failed to kill docker container for {task_id}: {e}") db = await get_db() - await db.log_audit( "task_cancelled", "Task cancelled by user", From 45e413d253bbfc36c7de78de8601fef793f914ee Mon Sep 17 00:00:00 2001 From: Avnithakur731-a Date: Sun, 31 May 2026 21:26:57 +0530 Subject: [PATCH 4/4] Restore cancelled task state transition --- backend/secuscan/executor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/secuscan/executor.py b/backend/secuscan/executor.py index 7ed91e00..3c3e45cb 100644 --- a/backend/secuscan/executor.py +++ b/backend/secuscan/executor.py @@ -637,6 +637,14 @@ async def cancel_task(self, task_id: str) -> bool: logger.error(f"Failed to kill docker container for {task_id}: {e}") db = await get_db() + await db.execute( + "UPDATE tasks SET status = ?, completed_at = ? WHERE id = ?", + (TaskStatus.CANCELLED.value, datetime.now().isoformat(), task_id) + ) + + await self._broadcast(task_id, "status", TaskStatus.CANCELLED.value) + + await self._invalidate_cached_views() await db.log_audit( "task_cancelled", "Task cancelled by user",