Skip to content

Make cancellation propagation atomic - #1613

Open
Clyraz wants to merge 1 commit into
microsoft:masterfrom
Clyraz:atomic-cancellation-propagation
Open

Make cancellation propagation atomic#1613
Clyraz wants to merge 1 commit into
microsoft:masterfrom
Clyraz:atomic-cancellation-propagation

Conversation

@Clyraz

@Clyraz Clyraz commented Aug 2, 2026

Copy link
Copy Markdown

Fixes the 4th case mentioned in #1609:

  • Coroutine already cancelled when a co_await starts.

I added a new state "cancelled_ptr" which will be used after cancelling.
Now the canceller will be invoked immediately if the previous value wasn't nullptr.

Copilot AI review requested due to automatic review settings August 2, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a remaining cancellation race in the coroutine cancellation propagation machinery by making cancellation “sticky” and ensuring newly-registered cancellers run immediately when a coroutine has already been cancelled.

Changes:

  • Update set_canceller to invoke the canceller immediately when registration fails because cancellation has already occurred / is in progress.
  • Introduce a new sentinel state (cancelled_ptr) and update cancel()/revoke_canceller() to use it so cancellation remains observable for future awaits.
  • Refine atomic state transitions in cancel() to avoid clobbering in-progress cancellation and to record post-cancel state.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants