Skip to content

When withTimeout hits a timeout, don’t wait for cooperative cancellation before returning #1730

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
Oct 1, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Sep 30, 2024

Previously, when we hit the timeout in withTimeout, we just cancelled body but relied on cooperative cancellation before the caller could continue. Since the caller is obviously no longer interested in the operation, we can return with CancellationError immediately.

Fixes #883
rdar://116705684

@ahoppen
Copy link
Member Author

ahoppen commented Sep 30, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 30, 2024

@swift-ci Please test Linux

@ktoso
Copy link
Contributor

ktoso commented Sep 30, 2024

Heh, you might want to consider renaming this to withUnstructuredTimeout or something like that. Giving up structured concurrency should be explicit I think as you lost priority escalation here.

@ahoppen ahoppen enabled auto-merge September 30, 2024 22:32
@ahoppen ahoppen disabled auto-merge September 30, 2024 22:32
…ation before returning

Previously, when we hit the timeout in `withTimeout`, we just cancelled `body` but relied on cooperative cancellation before the caller could continue. Since the caller is obviously no longer interested in the operation, we can return with `CancellationError` immediately.

Fixes swiftlang#883
rdar://116705684
@ahoppen ahoppen force-pushed the finish-immediately-timeout branch from 50d527d to 86653b3 Compare September 30, 2024 22:55
@ahoppen
Copy link
Member Author

ahoppen commented Sep 30, 2024

Good catch, @ktoso. I implemented priority propagation now.

@ahoppen
Copy link
Member Author

ahoppen commented Sep 30, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 30, 2024

@swift-ci Please test Windows

@ktoso
Copy link
Contributor

ktoso commented Oct 1, 2024

That does the trick with the hot loop around task.priority... tbh I'd rather just admit this drops structured concurrency, but if you've happy with this then your call.

We should provide a built-in operation for this soon, the while-true loop is very wasteful 😭

@ahoppen
Copy link
Member Author

ahoppen commented Oct 1, 2024

I would be very happy to see native implementations of all the async utilities I have in here. But until then, I’ve got to implement them in the best way I can…

@ahoppen ahoppen merged commit 9a3a0df into swiftlang:main Oct 1, 2024
3 checks passed
@ahoppen ahoppen deleted the finish-immediately-timeout branch October 1, 2024 16:53
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.

If request is cancelled, stop waiting for a response from sourcekitd/clangd
3 participants