Skip to content

Commit 2e8c99d

Browse files
authored
A few random stability/precompile improvements (#1030)
* migrate global -> Ref, should help type inference * mark several definition checks with `@static` * fix scoping issue with timeout definition
1 parent 8dc7039 commit 2e8c99d

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

src/ConnectionPool.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,24 @@ end
452452

453453
const nosslconfig = SSLConfig()
454454
const nosslcontext = Ref{OpenSSL.SSLContext}()
455-
default_sslconfig = nothing
456-
noverify_sslconfig = nothing
455+
const default_sslconfig = Ref{Union{Nothing, SSLConfig}}(nothing)
456+
const noverify_sslconfig = Ref{Union{Nothing, SSLConfig}}(nothing)
457457

458458
function global_sslconfig(require_ssl_verification::Bool)::SSLConfig
459-
global default_sslconfig
460-
global noverify_sslconfig
461-
if default_sslconfig === nothing
462-
default_sslconfig = SSLConfig(true)
463-
noverify_sslconfig = SSLConfig(false)
459+
if default_sslconfig[] === nothing
460+
default_sslconfig[] = SSLConfig(true)
461+
noverify_sslconfig[] = SSLConfig(false)
464462
end
465463
if haskey(ENV, "HTTP_CA_BUNDLE")
466-
MbedTLS.ca_chain!(default_sslconfig, MbedTLS.crt_parse(read(ENV["HTTP_CA_BUNDLE"], String)))
464+
MbedTLS.ca_chain!(default_sslconfig[], MbedTLS.crt_parse(read(ENV["HTTP_CA_BUNDLE"], String)))
467465
elseif haskey(ENV, "CURL_CA_BUNDLE")
468-
MbedTLS.ca_chain!(default_sslconfig, MbedTLS.crt_parse(read(ENV["CURL_CA_BUNDLE"], String)))
466+
MbedTLS.ca_chain!(default_sslconfig[], MbedTLS.crt_parse(read(ENV["CURL_CA_BUNDLE"], String)))
469467
end
470-
return require_ssl_verification ? default_sslconfig : noverify_sslconfig
468+
return require_ssl_verification ? default_sslconfig[] : noverify_sslconfig[]
471469
end
472470

473471
function global_sslcontext()::OpenSSL.SSLContext
474-
if isdefined(OpenSSL, :ca_chain!)
472+
@static if isdefined(OpenSSL, :ca_chain!)
475473
if haskey(ENV, "HTTP_CA_BUNDLE")
476474
sslcontext = OpenSSL.SSLContext(OpenSSL.TLSClientMethod())
477475
OpenSSL.ca_chain!(sslcontext, ENV["HTTP_CA_BUNDLE"])

src/IOExtras.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@ _doc = """
5151
5252
Signal start/end of write or read operations.
5353
"""
54-
if isdefined(Base, :startwrite)
54+
@static if isdefined(Base, :startwrite)
5555
"$_doc"
5656
Base.startwrite(io) = nothing
5757
else
5858
"$_doc"
5959
startwrite(io) = nothing
6060
end
6161

62-
if isdefined(Base, :closewrite)
62+
@static if isdefined(Base, :closewrite)
6363
"$_doc"
6464
Base.closewrite(io) = nothing
6565
else
6666
"$_doc"
6767
closewrite(io) = nothing
6868
end
6969

70-
if isdefined(Base, :startread)
70+
@static if isdefined(Base, :startread)
7171
"$_doc"
7272
Base.startread(io) = nothing
7373
else
7474
"$_doc"
7575
startread(io) = nothing
7676
end
7777

78-
if isdefined(Base, :closeread)
78+
@static if isdefined(Base, :closeread)
7979
"$_doc"
8080
Base.closeread(io) = nothing
8181
else

src/Parsers.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ const unhex = Int8[
351351
function __init__()
352352
# FIXME Consider turing off `PCRE.UTF` in `Regex.compile_options`
353353
# https://github.com/JuliaLang/julia/pull/26731#issuecomment-380676770
354-
nt = isdefined(Base.Threads, :maxthreadid) ? Threads.maxthreadid() : Threads.nthreads()
354+
nt = @static if isdefined(Base.Threads, :maxthreadid)
355+
Threads.maxthreadid()
356+
else
357+
Threads.nthreads()
358+
end
355359
resize!(empty!(status_line_regex), nt)
356360
resize!(empty!(request_line_regex), nt)
357361
resize!(empty!(header_field_regex), nt)

src/Servers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ After `reuse_limit + 1` transactions, signal `final_transaction` to the
410410
transaction handler, which will close the connection.
411411
"""
412412
function handle_connection(f, c::Connection, listener, readtimeout, access_log)
413+
wait_for_timeout = Ref{Bool}(true)
413414
if readtimeout > 0
414-
wait_for_timeout = Ref{Bool}(true)
415415
@async check_readtimeout(c, readtimeout, wait_for_timeout)
416416
end
417417
try

0 commit comments

Comments
 (0)