JuliaComputing / OpenAPI.jl

OpenAPI helper and code generator for Julia
Other
41 stars 7 forks source link

Throwing InterruptException to download task not a good idea #81

Open tanmaykm opened 3 weeks ago

tanmaykm commented 3 weeks ago

Interrupting the download task by scheduling an InterruptException on to it, like what we do here is not a good idea. It can lead to data race conditions and corruption.

We need to replace it with something that is safe. Ref https://github.com/JuliaLang/Downloads.jl/issues/255

vtjnash commented 3 weeks ago

It looks like the Downloads code normally provides 2 APIs for this. One difficult option is to call done! on the Easy object handle inside Downloads. It is very difficult to access this object, either via an easy_hook or progress callback:

downloader = Downloads.Downloader()
downloader.easy_hook = (easy, info) -> global current_download = easy

Or an easy option is to call close(output), which will automatically trigger the safe destruction of the download object the next time any output is received (or if the timeout is reached or other error occurs)

tanmaykm commented 3 weeks ago

Yeah, but this feels inadequate... can't think of a good way to have parallel requests and keep track of the easy handle without Downloads.jl exposing some nicer way to do that.

I have put up https://github.com/JuliaLang/Downloads.jl/pull/256 with a solution that we discussed for https://github.com/JuliaLang/Downloads.jl/issues/255. We can probably switch to something like that once it is available?