Skip to content

Commit eea68fc

Browse files
committed
Fix precompile
1 parent 2725fc5 commit eea68fc

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
2020

2121
[compat]
2222
JSON = "0.21.4"
23+
LibAwsIO = "1.2.0"
2324
PrecompileTools = "1.2.1"
2425
julia = "1.10"
2526

src/HTTP.jl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,37 @@ function Base.getproperty(e::StatusError, s::Symbol)
5252
end
5353
end
5454

55-
const LOGGER_FILE_REF = Ref{Libc.FILE}()
56-
const LOGGER_OPTIONS = Ref{aws_logger_standard_options}()
57-
const LOGGER = Ref{Ptr{Cvoid}}(C_NULL)
58-
5955
#NOTE: this is global process logging in the aws-crt libraries; not appropriate for request-level
6056
# logging, but more for debugging the library itself
61-
function set_log_level!(level::Integer)
57+
mutable struct AwsLogger
58+
ptr::Ptr{aws_logger}
59+
file_ref::Libc.FILE
60+
options::aws_logger_standard_options
61+
function AwsLogger(level::Integer, allocator::Ptr{aws_allocator})
62+
fr = Libc.FILE(Libc.RawFD(1), "w")
63+
opts = aws_logger_standard_options(aws_log_level(0), C_NULL, Ptr{Libc.FILE}(fr.ptr))
64+
x = new(Ptr{aws_logger}(aws_mem_acquire(allocator, 64)), fr, opts)
65+
aws_logger_init_standard(x.ptr, allocator, FieldRef(x, :options)) != 0 && aws_throw_error()
66+
aws_logger_set(x.ptr)
67+
return finalizer(x) do x
68+
aws_logger_clean_up(x.ptr)
69+
aws_mem_release(allocator, x.ptr)
70+
end
71+
end
72+
end
73+
74+
const LOGGER = Ref{AwsLogger}()
75+
76+
function set_log_level!(level::Integer, allocator::Ptr{aws_allocator}=default_aws_allocator())
6277
@assert 0 <= level <= 7 "log level must be between 0 and 7"
63-
@assert aws_logger_set_log_level(LOGGER[], aws_log_level(level)) == 0
78+
LOGGER[] = AwsLogger(level, allocator)
79+
@assert aws_logger_set_log_level(LOGGER[].ptr, aws_log_level(level)) == 0
6480
return
6581
end
6682

6783
function __init__()
6884
allocator = default_aws_allocator()
6985
LibAwsHTTP.init(allocator)
70-
# initialize logger
71-
LOGGER[] = aws_mem_acquire(allocator, 64)
72-
LOGGER_FILE_REF[] = Libc.FILE(Libc.RawFD(1), "w")
73-
LOGGER_OPTIONS[] = aws_logger_standard_options(aws_log_level(3), C_NULL, Ptr{Libc.FILE}(LOGGER_FILE_REF[].ptr))
74-
@assert aws_logger_init_standard(LOGGER[], allocator, LOGGER_OPTIONS) == 0
75-
aws_logger_set(LOGGER[])
7686
# intialize c functions
7787
on_acquired[] = @cfunction(c_on_acquired, Cvoid, (Ptr{Cvoid}, Cint, Ptr{aws_retry_token}, Ptr{Cvoid}))
7888
# on_shutdown[] = @cfunction(c_on_shutdown, Cvoid, (Ptr{Cvoid}, Cint, Ptr{Cvoid}))

src/client/client.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,13 @@ function getclient(key::ClientSettings, clients::Clients=CLIENTS)
231231
return client
232232
end
233233
end
234-
end
234+
end
235+
236+
function close_all_clients!(clients::Clients=CLIENTS)
237+
Base.@lock clients.lock begin
238+
for client in values(clients.clients)
239+
finalize(client)
240+
end
241+
empty!(clients.clients)
242+
end
243+
end

src/precompile.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ try
3030
@info "HTTP server shut down"
3131
yield() # needed on 1.9 to avoid some issue where it seems a task doesn't stop before serialization
3232
server = nothing
33+
close_all_clients!()
34+
close_default_aws_server_bootstrap!()
35+
close_default_aws_client_bootstrap!()
36+
close_default_aws_host_resolver!()
37+
close_default_aws_event_loop_group!()
3338
end
3439
end
3540
catch e

0 commit comments

Comments
 (0)