Skip to content

Don’t start executing a task when cancelToBeRescheduled is called before execute #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 31, 2024

QueuedTask.execute is called from a detached task in TaskScheduler.poke but we insert it into the currentlyExecutingTasks queue beforehand. This left a short windows in which we could cancel the task to reschedule it before it actually started executing.

Change QueuedTask to just return immediately from execute if it has been cancelled to be rescheduled beforehand.

@ahoppen ahoppen requested review from bnbarham and hamishknight May 31, 2024 01:55
@ahoppen ahoppen requested a review from benlangmuir as a code owner May 31, 2024 01:55
@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2024

@swift-ci Please test

@glessard
Copy link

@swift-ci please test

@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2024

@swift-ci Please test macOS

ahoppen added 2 commits May 31, 2024 18:04
…ead of an atomic

It’s only modified from method isolated to `QueuedTask`, so there’s no need for it to be an `AtomicBool`.
…efore `execute`

`QueuedTask.execute` is called from a detached task in `TaskScheduler.poke` but we insert it into the `currentlyExecutingTasks` queue beforehand. This left a short windows in which we could cancel the task to reschedule it before it actually started executing.

Change `QueuedTask` to just return immediately from `execute` if it has been cancelled to be rescheduled beforehand.
@ahoppen ahoppen force-pushed the cancel-task-before-execution-started branch from 8112854 to cc1280f Compare June 1, 2024 01:19
@ahoppen
Copy link
Member Author

ahoppen commented Jun 1, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jun 1, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 0ee2405 into swiftlang:main Jun 1, 2024
3 checks passed
@ahoppen ahoppen deleted the cancel-task-before-execution-started branch June 1, 2024 04:24
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.

4 participants