question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Task.chain cancellation semantics

See original GitHub issue

I have a series of tasks that are chained 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 chained 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robotlolitacommented, Jan 21, 2018

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.

0reactions
javamonncommented, Feb 17, 2018

@robotlolita 2.2.0-alpha1 does resolve the issues I was seeing. Thanks for the patch!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PPLX Task Cancellation Semantics · Issue #564 - GitHub
Consider the task chain A > B > C. Once B is cancelled, C will only execute once A completes. As consequence, B's...
Read more >
An Empirical Study of Task Cancellation Patterns and Failures
This essentially allows multiple cancel flags for one thread and hence can embed more semantic information inside each flag. However, it is also ......
Read more >
Async Cancellation I — 2021-11-10 - Yoshua Wuyts
This means that in order to cancel a chain of future, all we need to do is to drop it, and all resources...
Read more >
Proposal to add cancellation abilities for Async/Await - Pitches
The cancel scope has a cancel() method that can be used to explicitly cancel all unresolved tasks. When cancel() is called on a...
Read more >
Perspectives on Async Cancellation - Eric Holk
Whereas in most languages with async and cancellation, cancellation requires doing something such as calling .cancel() on the task, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found