Skip to content

[Concurrency] prevent races in task cancellation #38404

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
merged 1 commit into from
Jul 16, 2021

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Jul 15, 2021

This fixes two kinds of races with withTaskCancellationHandler:

  • one kind where we might have never run a handler
  • another kind where a naive fix would have potentially run the handler multiple times (twice)

Many details inside the PR.

Resolves rdar://78177513

@ktoso ktoso requested review from rjmccall, drexin and jckarter and removed request for rjmccall July 15, 2021 11:38
@ktoso ktoso force-pushed the wip-task-cancellation-double branch from 6790157 to 64f13ed Compare July 15, 2021 11:39
@ktoso ktoso force-pushed the wip-task-cancellation-double branch 2 times, most recently from be19b86 to 5dec799 Compare July 15, 2021 11:55
@ktoso
Copy link
Contributor Author

ktoso commented Jul 15, 2021

@swift-ci please smoke test

@ktoso
Copy link
Contributor Author

ktoso commented Jul 15, 2021

Windows Building remotely on windows-server-2019-vs-4 (windows-server-2019)ERROR: windows-server-2019-vs-4 seems to be offline

@ktoso ktoso force-pushed the wip-task-cancellation-double branch 2 times, most recently from 8d30552 to 9d5be78 Compare July 15, 2021 23:28
@ktoso ktoso force-pushed the wip-task-cancellation-double branch from 9d5be78 to e8888f7 Compare July 15, 2021 23:29
@ktoso
Copy link
Contributor Author

ktoso commented Jul 15, 2021

@swift-ci please smoke test and merge

void run(JobPriority newPriority) {
Function(Argument, newPriority);
}
void run(JobPriority newPriority) { Function(Argument, newPriority); }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(The formatting changes are by git-clang-format)


// else, the task was already cancelled, so while the record was added,
// we must run it immediately here since no other task will trigger it.
record->run();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change™.

We used to do this in a racy way in Swift but have to do so in here, based on the return of addStatusRecord

@swift-ci swift-ci merged commit d73d8a6 into swiftlang:main Jul 16, 2021
@ktoso ktoso added the concurrency Feature: umbrella label for concurrency language features label Jul 16, 2021
@rjmccall
Copy link
Contributor

It's a bit unfortunate that this PR has a ton of unrelated reformatting in it.

@rjmccall
Copy link
Contributor

Otherwise the fix looks good, thanks!

@ktoso ktoso deleted the wip-task-cancellation-double branch July 19, 2021 01:04
@ktoso
Copy link
Contributor Author

ktoso commented Jul 19, 2021

Thanks for review!

It's a bit unfortunate that this PR has a ton of unrelated reformatting in it.

Yeah... :| Perhaps I misused git-clang-format? Only discovered it this week to be honest heh; maybe I had applied it to the wrong commit...? I'll double check next time if it did the right thing, I kind of want it as a post-commit hook hmmm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants