-
Notifications
You must be signed in to change notification settings - Fork 180
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
How to close all cached connections #1137
Comments
Hmmmm, yeah, you're right that we don't actually close the connections when you call I think I would suggest that when you call |
Thanks, but I couldn't get rid of the warnings. Your example has a mismatched quote, so I tried the following permutations: header=["Connection"=>"close"]
header=["Connection=>close"]
header=["Connection"=>close]
header=[HTTP.Connection=>close]
header=[HTTP.Connection=>"close"] I am indeed using |
In case it is helpful, here is a MWE project: module HttpPrecompile
using HTTP, PrecompileTools
@setup_workload begin
@compile_workload begin
@info "Start precompile"
HTTP.get("https://www.google.com"; header=["Connection"=>"close"])
#HTTP.Connections.closeall()
#@show HTTP.Connections.OPENSSL_POOL[].keyedvalues
#foreach(vs -> foreach(close, vs), values(HTTP.Connections.OPENSSL_POOL[].keyedvalues))
@info "Precompile done"
end
end
end # module HttpPrecompile |
Hmmm, this is a bit janky, but I think should work: body = UInt8[]
resp = HTTP.open("GET", "https://www.github.com") do http
while !eof(http)
append!(body, readavailable(http)
end
close(HTTP.Connections.getrawstream(http))
end
|
Thanks, this prevents precompile from warning about dangling resources. Since I needed the body I also added This still seems to rely on internals though ( Any chance (a more convenient version of) it could be put in the public API? |
Please specify the following versions when submitting a bug report:
Is there a way to explicitly close all connections, including the ones which are globally cached in
Connections.jl
?There is
Connections.closeall()
but it only seems to empty the pools with the references but does not actually close the connections before doing. Could this be a bug or is it the intended behaviour for some reason? It seems like it would cause the connections to leak.Background is that I have a package which does need to query a webpage as part of the computations it does (for reasons beyond my control) and when I use
PrecompileTools
I get warnings like this:Fwiw, the precompilation does always complete in reasonable time (maybe the connections are closed when gc:ed?) and I get pretty nice speedups from it, so this is mostly about not getting the warning.
I have tried putting
HTTP.Connections.closeall()
last in the precompile script but it did not help. However, this helped:foreach(vs -> foreach(close, vs), values(HTTP.Connections.OPENSSL_POOL[].keyedvalues))
, but I don't feel comfortable having that code in there.The text was updated successfully, but these errors were encountered: