[train] Fix exception queue race condition in ThreadRunner#57249
Merged
justinvyu merged 8 commits intoray-project:masterfrom Oct 7, 2025
Merged
[train] Fix exception queue race condition in ThreadRunner#57249justinvyu merged 8 commits intoray-project:masterfrom
justinvyu merged 8 commits intoray-project:masterfrom
Conversation
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a race condition in the ThreadRunner where an exception in the user's target function could be missed, causing a failed run to appear successful. The fix, which involves joining the monitor thread before the target function's thread completes, is correct and robustly implemented. The removal of the manual _is_running flag in favor of thread.is_alive() simplifies the code and improves reliability. The accompanying tests are excellent, using threading.Event to deterministically reproduce the race condition and validate the fix. I have one minor suggestion to improve code clarity in the tests.
TimothySeah
approved these changes
Oct 7, 2025
Contributor
TimothySeah
left a comment
There was a problem hiding this comment.
Nice, thanks for the fix!
matthewdeng
approved these changes
Oct 7, 2025
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
…into fix_exc_queue_race
liulehui
pushed a commit
to liulehui/ray
that referenced
this pull request
Oct 9, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com>
joshkodi
pushed a commit
to joshkodi/ray
that referenced
this pull request
Oct 13, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com> Signed-off-by: Josh Kodi <joshkodi@gmail.com>
ArturNiederfahrenhorst
pushed a commit
to ArturNiederfahrenhorst/ray
that referenced
this pull request
Oct 13, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com>
justinyeh1995
pushed a commit
to justinyeh1995/ray
that referenced
this pull request
Oct 20, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com>
xinyuangui2
pushed a commit
to xinyuangui2/ray
that referenced
this pull request
Oct 22, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com> Signed-off-by: xgui <xgui@anyscale.com>
landscapepainter
pushed a commit
to landscapepainter/ray
that referenced
this pull request
Nov 17, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com>
Aydin-ab
pushed a commit
to Aydin-ab/ray-aydin
that referenced
this pull request
Nov 19, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com> Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Future-Outlier
pushed a commit
to Future-Outlier/ray
that referenced
this pull request
Dec 7, 2025
…ct#57249) This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the `TrainController`, which results in the run finishing successfully when it shouldn't. The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then `thread_runner.get_error()` always returns the final value. --------- Signed-off-by: Justin Yu <justinvyu@anyscale.com> Signed-off-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: matthewdeng <matthew.j.deng@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: matthewdeng <matt@anyscale.com> Signed-off-by: Future-Outlier <eric901201@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a race condition where an exception raised directly from the user target function doesn't get propagated to the
TrainController, which results in the run finishing successfully when it shouldn't.The fix is to join the monitor queue before before considering the target function finished. This ensures that any outstanding exception is processed. If is_running=False, then
thread_runner.get_error()always returns the final value.Problem
is_running = False._excattribute after the poll status call has finished. The controller sees(finished=True, error=None)and thinks that the run succeeded even though the worker errored.