From 841ac8f14a775426d96e88d237b82d3789633733 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Thu, 25 Feb 2021 17:34:59 -0500 Subject: [PATCH 1/2] Stop the grace timer iff adding first handle (fix #99) Using `multi.handle` to decide whether we need to stop the grace period timer or not is confusing; the clearest criterion for whether we need to start or stop that timer is whether the `multi.easies` vector is empty, so this patch uses that criterion instead, thereby fixing #99. --- src/Curl/Multi.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 From e6fa856dbb926932b2466e4c1b4df3d86b3eeec8 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 25 Feb 2021 17:47:13 -0500 Subject: [PATCH 2/2] Test for #99 from Tim's PR --- test/runtests.jl | 6 ++++++ 1 file changed, 6 insertions(+) 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