diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index f16e365..238aa4a 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -18,7 +18,7 @@ mutable struct Multi end function init!(multi::Multi) - uv_timer_stop(multi.timer) + multi.handle != C_NULL && return multi.handle = curl_multi_init() add_callbacks(multi) set_defaults(multi) @@ -42,9 +42,12 @@ end function add_handle(multi::Multi, easy::Easy) lock(multi.lock) do - isempty(multi.easies) && preserve_handle(multi) - multi.handle == C_NULL && init!(multi) + if isempty(multi.easies) + preserve_handle(multi) + uv_timer_stop(multi.timer) # stop grace timer + end push!(multi.easies, easy) + init!(multi) @check curl_multi_add_handle(multi.handle, easy.handle) end end diff --git a/test/runtests.jl b/test/runtests.jl index 1803ea8..ca885bb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -421,6 +421,12 @@ include("setup.jl") head = String(read!(open(file), Vector{UInt8}(undef, 16))) @test head == "\x1f\x8b\b\0\xa5T.\\\x02\x03\xec]{s۶" end + + @testset "grace cleanup" begin + dl = Downloader(grace=1) + Downloads.download("https://httpbingo.org/drip"; downloader=dl) + Downloads.download("https://httpbingo.org/drip"; downloader=dl) + end end Downloads.DOWNLOADER[] = nothing