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

Make sure we don't clean up an active handle during a next download. #101

Closed
wants to merge 1 commit into from

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Feb 25, 2021

Fixes #99

@codecov-io
Copy link

codecov-io commented Feb 25, 2021

Codecov Report

Merging #101 (b8d1ea0) into master (af6864d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   92.96%   92.98%   +0.02%     
==========================================
  Files           5        5              
  Lines         483      485       +2     
==========================================
+ Hits          449      451       +2     
  Misses         34       34              
Impacted Files Coverage Δ
src/Curl/Multi.jl 95.83% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af6864d...b8d1ea0. Read the comment docs.

@giordano
Copy link
Contributor

Is any of the tests in #99 reproducible in CI?

@maleadt maleadt force-pushed the tb/reuse_grace_cleanup branch from b8d1ea0 to fa24496 Compare February 25, 2021 15:19
@maleadt
Copy link
Member Author

maleadt commented Feb 25, 2021

Yes, I've added the MWE as a test.

@fredrikekre
Copy link
Member

Does it also fix #95 or are they completely separate issues? Have you tried enabling HTTP/2 wich this patch?

@maleadt
Copy link
Member Author

maleadt commented Feb 25, 2021

Does it also fix #95 or are they completely separate issues? Have you tried enabling HTTP/2 wich this patch?

That seems very possible, but I couldn't reproduce with HTTP 2.0 re-enabled (and this patch either disabled or enabled). Could you try on your system?

else
# if reusing a multi, it's possible we had queued up a cleanup of the handle.
# stop that timer so that we don't accidentaly clean up during another download.
uv_timer_stop(multi.timer)
Copy link
Member

Choose a reason for hiding this comment

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

Seems better to just hoist the uv_timer_stop(multi.timer) call out of init!.

Copy link
Member

Choose a reason for hiding this comment

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

I.e. something like this:

diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl
index f16e365..2a5f538 100644
--- a/src/Curl/Multi.jl
+++ b/src/Curl/Multi.jl
@@ -18,7 +18,6 @@ mutable struct Multi
 end

 function init!(multi::Multi)
-    uv_timer_stop(multi.timer)
     multi.handle = curl_multi_init()
     add_callbacks(multi)
     set_defaults(multi)
@@ -43,7 +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 multi.handle == C_NULL
+            init!(multi)
+        else
+            # stop grace timer
+            uv_timer_stop(multi.timer)
+        end
         push!(multi.easies, easy)
         @check curl_multi_add_handle(multi.handle, easy.handle)
     end

The remaining question is whether the call to uv_timer_stop should happen on every added handle or only the first one (when multi.handle == C_NULL). I suspect the latter, but I'm not 100% sure. If so, then this code was calling uv_timer_stop exactly when it shouldn't and not calling it when it should 😬

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.

Another download hang
5 participants