Task.chain cancellation semantics
See original GitHub issueI have a series of tasks that are chain
ed together so that they execute on after another. At some point, I may wish to stop the execution of the series of tasks, so I call cancel
on the TaskExecution
object I get from calling run
on the chain
ed tasks. As expected, the onCancelled
callback fires on the listener attached to the TaskExecution
object. However, The onCancelled
callback on the tasks themselves don’t appear to fire, and the tasks continue to execute.
Steps to reproduce
https://runkit.com/javamonn/5a65014051c1e2001226dd28
Expected behaviour
When I call cancel
on the ExecutionObject
of several tasks that have been chained together and ran, I would expect the onCancelled
callback of the currently executing task in that series to be called or isCancelled
to be set, and that tasks that are chained later in the series to not execute at all, as the task did not resolve successfully.
Observed behaviour
You can see the attached logs on the runkit example. When I call cancel
on the ExecutionObject
, the attached listener fires the onCancelled
object correctly, but the task series continues executing, onCancelled
is not called and isCancelled
is not set, and the currently executing task at the time of cancellation ends up throwing an error when it (incorrectly) tries to resolve
itself.
Environment
N / A, attached runkit.
Additional information
I’m not sure if this is simply a misunderstanding of the semantics of cancelling a series of tasks that are chained together. If so, I apologize for the spurious issue!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
The semantics aren’t well defined (which is not a good thing, I have to take the time to define them properly), but cancelling the execution should cancel all of the pending tasks in a chain. There seems to be an error in the propagation when part of the chain is already settled, though.
If the cancellation happens before task A settles, then all tasks in the chain are cancelled. If task A settles first, then cancellation of all other tasks in the chain is skipped.
I’ll take a better look at why this is happening in February, since I have to finish preparing a talk for a conference next week.
@robotlolita
2.2.0-alpha1
does resolve the issues I was seeing. Thanks for the patch!