From 777b784dde077defd0aea58b598241f95146152a Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 24 Aug 2023 14:33:32 +0200 Subject: [PATCH] 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 https://github.com/JuliaLang/julia/commit/40c622b7e66a88c05d8892222126f1d13851bc62#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. --- stdlib/Distributed/src/process_messages.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/Distributed/src/process_messages.jl b/stdlib/Distributed/src/process_messages.jl index 7bbf7cfde943b..e68e05b9db52b 100644 --- a/stdlib/Distributed/src/process_messages.jl +++ b/stdlib/Distributed/src/process_messages.jl @@ -210,6 +210,9 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool) handle_msg(msg, header, r_stream, w_stream, version) end catch e + werr = worker_from_id(wpid) + oldstate = werr.state + # Check again as it may have been set in a message handler but not propagated to the calling block above if wpid < 1 wpid = worker_id_from_socket(r_stream) @@ -219,8 +222,6 @@ function message_handler_loop(r_stream::IO, w_stream::IO, incoming::Bool) println(stderr, e, CapturedException(e, catch_backtrace())) println(stderr, "Process($(myid())) - Unknown remote, closing connection.") elseif !(wpid in map_del_wrkr) - werr = worker_from_id(wpid) - oldstate = werr.state set_worker_state(werr, W_TERMINATED) # If unhandleable error occurred talking to pid 1, exit