Skip to content

Commit 777b784

Browse files
authored
fix a case of potentially use of undefined variable when handling error in distributed message processing (#51019)
There is a use of `oldstate` on line 244 which has the possibility of being undefined. This bug seems to have been introduced in 40c622b#diff-39fa44ff86c5b38bd6b9e7f60733b25724a9efd9221ca38f776ed3f3ab01dec2. I don't have a repro for this but this PR reverts back to the situation where `oldstate` is defined at the topmost level of the catch block as it was before the offending commit.
1 parent ce8acdd commit 777b784

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stdlib/Distributed/src/process_messages.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool)
210210
handle_msg(msg, header, r_stream, w_stream, version)
211211
end
212212
catch e
213+
werr = worker_from_id(wpid)
214+
oldstate = werr.state
215+
213216
# Check again as it may have been set in a message handler but not propagated to the calling block above
214217
if wpid < 1
215218
wpid = worker_id_from_socket(r_stream)
@@ -219,8 +222,6 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool)
219222
println(stderr, e, CapturedException(e, catch_backtrace()))
220223
println(stderr, "Process($(myid())) - Unknown remote, closing connection.")
221224
elseif !(wpid in map_del_wrkr)
222-
werr = worker_from_id(wpid)
223-
oldstate = werr.state
224225
set_worker_state(werr, W_TERMINATED)
225226

226227
# If unhandleable error occurred talking to pid 1, exit

0 commit comments

Comments
 (0)