Open taylor-curran opened 6 months ago
Thanks for the issue @taylor-curran! This is likely a bug in our cancellation cleanup service. We will investigate a fix for this!
I'm writing a flow for running Spark in k8s and I need this to correctly tear it down on cancellation. Additionally it would be nice if tasks has cancellation hooks too.. But at least sub flows should have it working.
Any update on this? At the moment no sub-flow hooks are triggered at all, when parent flow gets cancelled.
First check
Desired Behavior
When a parent flow is canceled, the child flow should also enter into a cancelling or canceled state.
For normal (not-deployed) subflows, the subflow does not cancel it crashes -- its the same behavior as a task that is running mid-cancellation of its flow.
For sub-deployments, the behavior is as expected, the subflow also enters into cancelling and then canceled state. ✅ This is likely because in the parent flow, I can return the state of the child flow. I think we test for this behavior.
Reasoning and Work-Arounds
Normal subflows are often used by teams using our databricks or dbt integrations. They often want cancellation of a parent flow to result in a cancellation of their databricks or dbt subflow. Its very common to have on_cancellation state change hooks that tear down resources in said databricks environments and the fact that these subflows don't inherit the state of their parent blocks them from building such automations.
A workaround is to set up on_crashed state change hooks, but crashes can represent different occurrences that may not warrant the tearing down of other resources in the same way that a cancellation would.
Reproduction
I made sure to set enhanced cancellation to True.
normal_subflows_served.py
normal_subflows_deployed_parent.py
`sub_deployment.py'
Error
Served Flow Run
Deployed Flow Run with Normal Subflow
Sub Deployment -- Expected Behavior ✅
Versions
Additional context
Potentially related #10947, #11055 -- though maybe these fixes only apply to sub deployments it seems where there is a separate infra for the child flow.