Skip to content

Commit 19b94b6

Browse files
committed
Replace the stdlib watcher task with a Timer
This needs to be shutdown cleanly or the lingering watcher task can cause hangs.
1 parent dbe70f6 commit 19b94b6

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

docs/src/_changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ CurrentModule = DistributedNext
77
This documents notable changes in DistributedNext.jl. The format is based on
88
[Keep a Changelog](https://keepachangelog.com).
99

10+
## Unreleased
11+
12+
### Fixed
13+
- Backported various fixes from Distributed ([#25]).
14+
- Fixed a lingering task that could cause hangs when exiting Distributed ([#51]).
15+
1016
## [v1.1.0] - 2025-08-02
1117

1218
### Fixed

src/DistributedNext.jl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ include("pmap.jl")
132132
include("managers.jl") # LocalManager and SSHManager
133133
include("precompile.jl")
134134

135+
_stdlib_watcher_timer::Union{Timer, Nothing} = nothing
136+
135137
function __init__()
138+
global _stdlib_watcher_timer
136139
init_parallel()
137140

138141
if ccall(:jl_generating_output, Cint, ()) == 0
@@ -141,20 +144,12 @@ function __init__()
141144
# cluster cookie has been set, which is most likely to have been done
142145
# through Distributed.init_multi() being called by Distributed.addprocs() or
143146
# something.
144-
watcher_task = Threads.@spawn while true
147+
_stdlib_watcher_timer = Timer(0; interval=1) do timer
145148
if _check_distributed_active()
146-
return
147-
end
148-
149-
try
150-
sleep(1)
151-
catch
152-
# sleep() may throw when the internal object it waits on is closed
153-
# as the process exits.
154-
return
149+
close(timer)
155150
end
156151
end
157-
errormonitor(watcher_task)
152+
atexit(() -> close(_stdlib_watcher_timer))
158153
end
159154
end
160155

0 commit comments

Comments
 (0)