Skip to content
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

gracefully cancel a request #256

Merged
merged 2 commits into from
Sep 3, 2024
Merged

Conversation

tanmaykm
Copy link
Member

Adds a way to gracefully cancel an ongoing request. The request method accepts an additional interrupt keyword which can be a Base.Event. When it is triggered, the curl_multi_remove_handle is invoked, which interrupts the easy handle gracefully. It closes the output and progress channels of the Easy handle to unblock the waiting request task, which then terminates with a RequestError.

Ref: #255

Adds a way to gracefully cancel an ongoing request. The `request` method accepts an additional `interrupt` keyword which can be a `Base.Event`. When it is triggered, the [`curl_multi_remove_handle`](https://curl.se/libcurl/c/curl_multi_remove_handle.html) is invoked, which interrupts the easy handle gracefully. It closes the `output` and `progress` channels of the `Easy` handle to unblock the waiting request task, which then terminates with a `RequestError`.

Ref: JuliaLang#255
@tanmaykm
Copy link
Member Author

Requesting some 👀 on this...
Maybe @KristofferC or @StefanKarpinski ?

@KristofferC KristofferC merged commit df33406 into JuliaLang:master Sep 3, 2024
18 checks passed
else
lock(multi.lock) do
check_multi_info(multi)
end
Copy link
Member

@topolarity topolarity Sep 3, 2024

Choose a reason for hiding this comment

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

Is this a related change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. When the easy handle is removed this callback is invoked with CURL_POLL_REMOVE. If I recollect, calling check_multi_info was required to clean up and unblock the request method that's blocking on some of the channels.

@KristofferC
Copy link
Member

@IanButterworth can we use this in Pkg downloads to not get all the curl errors if a user ctrl C during e.g. package downloading?

@IanButterworth
Copy link
Member

I'm not sure we can stop the curl async processes from receiving interrupts?

@IanButterworth
Copy link
Member

I think we'd need JuliaLang/julia#49541 to intercept it and then call this cancel?

tanmaykm added a commit to tanmaykm/Downloads.jl that referenced this pull request Sep 4, 2024
Cancelling an upload (PUT) request using the mechanism introduced in JuliaLang#256 was not effective. The upload task was not interrupted, which still blocks and the call to `request` does not return.
With this change, cancelling also closes the `input` stream of the request to unblock the upload task.

Also changed the `interrupted` variable to be an `Atomic{Bool}`. Ref discussion [here](JuliaLang#256 (comment)).
tanmaykm added a commit to tanmaykm/Downloads.jl that referenced this pull request Sep 4, 2024
Cancelling an upload (PUT) request using the mechanism introduced in JuliaLang#256 was not effective. The upload task was not interrupted, which still blocked and the call to `request` did not return.
With this change, cancelling also closes the `input` stream of the request to unblock the upload task.

Also changed the `interrupted` variable to be an `Atomic{Bool}`. Ref discussion [here](JuliaLang#256 (comment)).
tanmaykm added a commit to tanmaykm/Downloads.jl that referenced this pull request Sep 5, 2024
Cancelling an upload (PUT) request using the mechanism introduced in JuliaLang#256 was not effective. The upload task was not interrupted, which still blocked and the call to `request` did not return.
With this change, cancelling also closes the `input` stream of the request to unblock the upload task.

Also changed the `interrupted` variable to be an `Atomic{Bool}`. Ref discussion [here](JuliaLang#256 (comment)).
KristofferC pushed a commit that referenced this pull request Sep 9, 2024
Cancelling an upload (PUT) request using the mechanism introduced in #256 was not effective. The upload task was not interrupted, which still blocked and the call to `request` did not return.
With this change, cancelling also closes the `input` stream of the request to unblock the upload task.

Also changed the `interrupted` variable to be an `Atomic{Bool}`. Ref discussion [here](#256 (comment)).
tanmaykm added a commit to JuliaComputing/OpenAPI.jl that referenced this pull request Sep 24, 2024
Detect if we are using a newer version of Download.jl that supports interrupting of requests natively and use that instead of throwing `InterruptException`.

ref: JuliaLang/Downloads.jl#256 and JuliaLang/Downloads.jl#259

fixes: #81
tanmaykm added a commit to JuliaComputing/OpenAPI.jl that referenced this pull request Sep 24, 2024
Detect if we are using a newer version of Download.jl that supports interrupting of requests natively and use that instead of throwing `InterruptException`.

ref: JuliaLang/Downloads.jl#256 and JuliaLang/Downloads.jl#259

fixes: #81
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.

5 participants