Skip to content

Commit

Permalink
Use Base.errormonitor() to print the logs from @async tasks if th…
Browse files Browse the repository at this point in the history
…ey fail (#13)
  • Loading branch information
DilumAluthge authored Feb 19, 2025
1 parent ebed93d commit ee40fc7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/elastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export ElasticManager, elastic_worker

const HDR_COOKIE_LEN = Distributed.HDR_COOKIE_LEN

@static if Base.VERSION >= v"1.7-"
# Base.errormonitor() is only available in Julia 1.7+
my_errormonitor(t) = Base.errormonitor(t)
else
my_errormonitor(t) = nothing
end

struct ElasticManager <: ClusterManager
active::Dict{Int, WorkerConfig} # active workers
pending::Channel{TCPSocket} # to be added workers
Expand All @@ -31,15 +38,18 @@ struct ElasticManager <: ClusterManager

lman = new(Dict{Int, WorkerConfig}(), Channel{TCPSocket}(typemax(Int)), Set{Int}(), topology, getsockname(l_sock), printing_kwargs)

@async begin
t1 = @async begin
while true
let s = accept(l_sock)
@async process_worker_conn(lman, s)
t2 = @async process_worker_conn(lman, s)
my_errormonitor(t2)
end
end
end
my_errormonitor(t1)

@async process_pending_connections(lman)
t3 = @async process_pending_connections(lman)
my_errormonitor(t3)

lman
end
Expand Down

0 comments on commit ee40fc7

Please sign in to comment.