Skip to content

Ensure spawned libcoro tasks complete when cancelling - #1131

Merged
rapids-bot[bot] merged 2 commits into
rapidsai:mainfrom
wence-:wence/fix/dangling-futures
Jul 17, 2026
Merged

Ensure spawned libcoro tasks complete when cancelling#1131
rapids-bot[bot] merged 2 commits into
rapidsai:mainfrom
wence-:wence/fix/dangling-futures

Conversation

@wence-

@wence- wence- commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

If we are awaiting a libcoro task and are cancelled on the Python side, we currently just cancel the Python future leading to an asyncio warning when the C++ callback eventually fires to set a result. Furthermore, we might not end up waking C++ waiters if, for example, Python cancellation fails to successfully shut down a channel.

To mitigate against this for most awaitables that bridge from Python into C++, introduce new utilities to shutdown channels, and await a C++ spawned task, handling cancellation, and optionally running some cleanup before raising the cancellation error.

@wence-
wence- requested review from a team as code owners July 16, 2026 13:17
@wence-
wence- requested a review from bdice July 16, 2026 13:17
@wence- wence- added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jul 16, 2026
@wence-
wence- force-pushed the wence/fix/dangling-futures branch from 25da142 to 5f2b043 Compare July 16, 2026 14:43

@madsbk madsbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks very good

Comment thread python/rapidsmpf/rapidsmpf/streaming/core/cancellation.pyi
Comment thread python/rapidsmpf/rapidsmpf/streaming/core/cancellation.pyx Outdated
Comment thread python/rapidsmpf/rapidsmpf/streaming/core/actor.pyx Outdated
Comment thread python/rapidsmpf/rapidsmpf/streaming/core/actor.pyx
wence- added 2 commits July 16, 2026 16:12
If we are awaiting a libcoro task and are cancelled on the Python side, we
currently just cancel the Python future leading to an asyncio warning when
the C++ callback eventually fires to set a result. Furthermore, we might
not end up waking C++ waiters if, for example, Python cancellation fails to
successfully shut down a channel.

To mitigate against this for most awaitables that bridge from Python into
C++, introduce new utilities to shutdown channels, and await a C++ spawned
task, handling cancellation, and optionally running some cleanup before
raising the cancellation error.
@wence-
wence- force-pushed the wence/fix/dangling-futures branch from 5f2b043 to 06cca47 Compare July 16, 2026 15:14
@wence-
wence- requested a review from madsbk July 16, 2026 15:14

@vyasr vyasr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, otherwise LGTM.

Comment thread python/rapidsmpf/rapidsmpf/streaming/core/cancellation.pyx
@wence-

wence- commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 9e74387 into rapidsai:main Jul 17, 2026
66 checks passed
@wence-
wence- deleted the wence/fix/dangling-futures branch July 17, 2026 08:10
rapids-bot Bot pushed a commit that referenced this pull request Jul 17, 2026
If we are awaiting a libcoro task and are cancelled on the Python side, we currently just cancel the Python future leading to an asyncio warning when the C++ callback eventually fires to set a result. Furthermore, we might not end up waking C++ waiters if, for example, Python cancellation fails to successfully shut down a channel.

To mitigate against this for most awaitables that bridge from Python into C++, introduce new utilities to shutdown channels, and await a C++ spawned task, handling cancellation, and optionally running some cleanup before raising the cancellation error.

Backport of #1131 onto 26.08

Authors:
  - Lawrence Mitchell (https://github.com/wence-)

Approvers:
  - Mads R. B. Kristensen (https://github.com/madsbk)
  - Tom Augspurger (https://github.com/TomAugspurger)
  - Bradley Dice (https://github.com/bdice)

URL: #1133
rapids-bot Bot pushed a commit to NVIDIA/cudf that referenced this pull request Jul 22, 2026
…aitables (#23293)

To avoid cancellation in python leading to attempting to set a result on an already cancelled Future, use the new pattern introduced in rapidsai/rapidsmpf#1131

Authors:
  - Lawrence Mitchell (https://github.com/wence-)
  - Tom Augspurger (https://github.com/TomAugspurger)

Approvers:
  - Tom Augspurger (https://github.com/TomAugspurger)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #23293
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants