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

Mechanism to gracefully interrupt an ongoing Downloads.request #255

Closed
tanmaykm opened this issue Aug 24, 2024 · 4 comments
Closed

Mechanism to gracefully interrupt an ongoing Downloads.request #255

tanmaykm opened this issue Aug 24, 2024 · 4 comments

Comments

@tanmaykm
Copy link
Member

We often have APIs that stream results over a period of time. What would be a reliable way to interrupt such an ongoing Downloads.request?

From what I gather, interrupting the julia task is not ideal. So I think this has to be done using libcurl APIs. And probably Downloads.request needs to provide a mechanism to signal an interruption to it somehow. Putting up this issue for discussion and resolution.

@tanmaykm
Copy link
Member Author

Seems like curl_multi_remove_handle may be a way to interrupt an easy handle gracefully. The caller could probably pass an optional Base.Event to Downloads.request if it wants to interrupt it?

@vtjnash
Copy link
Member

vtjnash commented Aug 24, 2024

Sounds like a likely api from curl. The common way to handle it would be having downloads return a state object that you can interact with (ask progress, wait on, pause, close, etc) either as a different function or using the kwarg wait=false

tanmaykm added a commit to tanmaykm/Downloads.jl that referenced this issue Aug 27, 2024
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 added a commit to tanmaykm/Downloads.jl that referenced this issue Aug 27, 2024
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

I have put up #256 with an implementation of what we discussed here.

I felt that returning a state object from request method would be a significantly larger change, both in terms of code and also because it will change the API. For now this PR adds a single kwarg to allow cancelling. The async implementation can be a larger future PR.

@tanmaykm
Copy link
Member Author

Fixed by #256 and #259

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

No branches or pull requests

2 participants