From f6094bfbb70d9c6c9c819e97892a3bef3c58dca7 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 19 Dec 2024 17:56:46 +0000 Subject: [PATCH] Always close precompile server (#1209) --- src/precompile.jl | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index e9c53ad2..e104f736 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -22,22 +22,25 @@ try server = HTTP.serve!("0.0.0.0", _port; verbose = -1, listenany=true, sslconfig=sslconfig) do req HTTP.Response(200, ["Content-Encoding" => "gzip"], gzip_data("dummy response")) end - # listenany allows changing port if that one is already in use, so check the actual port - _port = HTTP.port(server) - url = "https://localhost:$_port" - - env = ["JULIA_NO_VERIFY_HOSTS" => "localhost", - "JULIA_SSL_NO_VERIFY_HOSTS" => nothing, - "JULIA_ALWAYS_VERIFY_HOSTS" => nothing] - withenv(env...) do - @compile_workload begin - HTTP.get(url); + try + # listenany allows changing port if that one is already in use, so check the actual port + _port = HTTP.port(server) + url = "https://localhost:$_port" + + env = ["JULIA_NO_VERIFY_HOSTS" => "localhost", + "JULIA_SSL_NO_VERIFY_HOSTS" => nothing, + "JULIA_ALWAYS_VERIFY_HOSTS" => nothing] + + withenv(env...) do + @compile_workload begin + HTTP.get(url); + end end + finally + HTTP.forceclose(server) + yield() # needed on 1.9 to avoid some issue where it seems a task doesn't stop before serialization + server = nothing end - - HTTP.forceclose(server) - yield() # needed on 1.9 to avoid some issue where it seems a task doesn't stop before serialization - server = nothing end catch e @info "Ignoring an error that occurred during the precompilation workload" exception=(e, catch_backtrace())