When you cancel a flow from the Prefect dashboard and the UI shows that the state has moved to "Cancelled," but you still see logs in the pod indicating progress, it can be due to a few reasons related to the nature of flow cancellation in Kubernetes environments:
1.
Delayed Cancellation on Kubernetes: The cancellation command might be executed, marking the flow as "Cancelled" in Prefect's system. However, the underlying Kubernetes pods (or other infrastructure) might still be running tasks. The infrastructure might not instantly shut down the tasks, leading to logs appearing even after cancellation.
2.
Infrastructure Cleanup: There could be a disconnect where the Prefect flow pod is terminated, but the associated Kubernetes pods (like Dask Scheduler or Worker pods) continue to exist, as seen in a known issue on GitHub (
Issue #12976). The flow pod might not send proper termination signals, leaving other infrastructure components orphaned.
3.
Enhanced Cancellation: Prefect is working on improving cancellation issues. You can try the experimental enhanced cancellation feature by setting
PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION=True
. This might address some of the cancellation enforcement issues by providing better control over the ongoing tasks.
For more information, you can refer to the source:
-
Prefect Flow Cancellation and Infrastructure
If the issue persists, consider filing a detailed report with Prefect's support or on their GitHub repository for a more tailored solution.