From c95804522205230223b81f0c51a39b36dbd99908 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Tue, 15 Jul 2025 11:42:02 -0400 Subject: [PATCH] Try a real URL first during precompile to avoid firewall warnings --- src/precompile.jl | 65 +++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index d6cc822d..1fdf1c16 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -10,36 +10,51 @@ try # Doesn't seem to be needed here, and might not be safe to call twice (here and during runtime) # ConnectionRequest.__init__() - gzip_data(data::String) = read(GzipCompressorStream(IOBuffer(data))) + # First try a real internet URL because the fallback of seting up a local server + # may trigger firewall warnings + internet_success = false + @compile_workload begin + try + HTTP.get("https://httpbin.org/status/200"; readtimeout=5); + internet_success = true + catch + # Internet request failed, will fallback to local server + end + end - # random port in the dynamic/private range (49152–65535) which are are - # least likely to be used by well-known services - _port = 57813 + # Only set up local server if internet request failed + if !internet_success + gzip_data(data::String) = read(GzipCompressorStream(IOBuffer(data))) - cert, key = joinpath.(@__DIR__, "../test", "resources", ("cert.pem", "key.pem")) - sslconfig = MbedTLS.SSLConfig(cert, key) + # random port in the dynamic/private range (49152–65535) which are are + # least likely to be used by well-known services + _port = 57813 - 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 - 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] - - @compile_workload begin - withenv(env...) do - HTTP.get(url); + cert, key = joinpath.(@__DIR__, "../test", "resources", ("cert.pem", "key.pem")) + sslconfig = MbedTLS.SSLConfig(cert, key) + + 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 + 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] + + @compile_workload begin + withenv(env...) do + 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 - 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 end catch e