Skip to content

[core] Deflake test_stop_job_timeout by stopping the job only after its SIGTERM handler is installed - #63726

Merged
edoakes merged 2 commits into
ray-project:masterfrom
Yicheng-Lu-llll:deflake-test-stop-job-timeout
May 29, 2026
Merged

edoakes merged 2 commits into
ray-project:masterfrom
Yicheng-Lu-llll:deflake-test-stop-job-timeout

Conversation

@Yicheng-Lu-llll

Copy link
Copy Markdown
Member

Description

test_stop_job_timeout basically wants to do the following:

  • The driver installs a SIGTERM handler and, once installed, prints log A.
  • We grep for log A to make sure the SIGTERM handler is installed.
  • We then stop the job with SIGTERM, and the driver should not exit on it.
  • The handler also prints log B, which we check to confirm the handler actually ran.

The problem is that grepping the log isn't reliable. Before launching the driver, the supervisor writes the entrypoint command into the log, and it includes the whole script source, including those two print A and B:

f"Running entrypoint for job {self._job_id}: {self._entrypoint}\n"

So A and B are already in the log before the driver runs a single line. So we might end up sending SIGTERM before the driver installs the handler.

So we use files instead: the driver creates one file after the handler is installed, and the handler creates another when it runs.

This flaky test also reproduces on my local Mac, and I verified it is stable after the fix.

…GTERM handler is installed

Signed-off-by: Yicheng Lu <[email protected]>
@Yicheng-Lu-llll
Yicheng-Lu-llll requested a review from a team as a code owner May 29, 2026 16:49
@Yicheng-Lu-llll Yicheng-Lu-llll added core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests labels May 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors test_stop_job_timeout in test_job_manager.py to use file-based indicators (ready_file and handled_file via tmp_path) instead of checking stdout logs to verify that the job is ready and that the SIGTERM signal was handled. A review comment suggests using .as_posix() instead of str() on the file paths to prevent backslash escaping issues on Windows platforms.

Signed-off-by: Yicheng Lu <[email protected]>
@edoakes

edoakes commented May 29, 2026

Copy link
Copy Markdown
Collaborator

The problem is that grepping the log isn't reliable. Before launching the driver, the supervisor writes the entrypoint command into the log, and it includes the whole script source

Omg, great find! I'm impressed

@edoakes
edoakes enabled auto-merge (squash) May 29, 2026 18:19
@edoakes
edoakes merged commit 25c1426 into ray-project:master May 29, 2026
4 checks passed
rueian pushed a commit to rueian/ray that referenced this pull request Jun 4, 2026
… its SIGTERM handler is installed (ray-project#63726)

## Description

`test_stop_job_timeout` basically wants to do the following:
- The driver installs a SIGTERM handler and, once installed, prints log
A.
- We grep for log A to make sure the SIGTERM handler is installed.
- We then stop the job with SIGTERM, and the driver should not exit on
it.
- The handler also prints log B, which we check to confirm the handler
actually ran.

The problem is that grepping the log isn't reliable. Before launching
the driver, the supervisor writes the entrypoint command into the log,
and it includes the whole script source, including those two print A and
B:

https://github.com/ray-project/ray/blob/13e1bd138a209c0d1a5c50843c4a6d45b198eb6b/python/ray/dashboard/modules/job/job_supervisor.py#L179

So A and B are already in the log before the driver runs a single line.
So we might end up sending SIGTERM before the driver installs the
handler.

So we use files instead: the driver creates one file after the handler
is installed, and the handler creates another when it runs.

This flaky test also reproduces on my local Mac, and I verified it is
stable after the fix.

---------

Signed-off-by: Yicheng Lu <[email protected]>
Co-authored-by: Yicheng Lu <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
… its SIGTERM handler is installed (ray-project#63726)

## Description

`test_stop_job_timeout` basically wants to do the following:
- The driver installs a SIGTERM handler and, once installed, prints log
A.
- We grep for log A to make sure the SIGTERM handler is installed.
- We then stop the job with SIGTERM, and the driver should not exit on
it.
- The handler also prints log B, which we check to confirm the handler
actually ran.

The problem is that grepping the log isn't reliable. Before launching
the driver, the supervisor writes the entrypoint command into the log,
and it includes the whole script source, including those two print A and
B:

https://github.com/ray-project/ray/blob/13e1bd138a209c0d1a5c50843c4a6d45b198eb6b/python/ray/dashboard/modules/job/job_supervisor.py#L179

So A and B are already in the log before the driver runs a single line.
So we might end up sending SIGTERM before the driver installs the
handler.

So we use files instead: the driver creates one file after the handler
is installed, and the handler creates another when it runs.

This flaky test also reproduces on my local Mac, and I verified it is
stable after the fix.

---------

Signed-off-by: Yicheng Lu <[email protected]>
Co-authored-by: Yicheng Lu <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
… its SIGTERM handler is installed (ray-project#63726)

## Description

`test_stop_job_timeout` basically wants to do the following:
- The driver installs a SIGTERM handler and, once installed, prints log
A.
- We grep for log A to make sure the SIGTERM handler is installed.
- We then stop the job with SIGTERM, and the driver should not exit on
it.
- The handler also prints log B, which we check to confirm the handler
actually ran.

The problem is that grepping the log isn't reliable. Before launching
the driver, the supervisor writes the entrypoint command into the log,
and it includes the whole script source, including those two print A and
B:

https://github.com/ray-project/ray/blob/13e1bd138a209c0d1a5c50843c4a6d45b198eb6b/python/ray/dashboard/modules/job/job_supervisor.py#L179

So A and B are already in the log before the driver runs a single line.
So we might end up sending SIGTERM before the driver installs the
handler.

So we use files instead: the driver creates one file after the handler
is installed, and the handler creates another when it runs.

This flaky test also reproduces on my local Mac, and I verified it is
stable after the fix.

---------

Signed-off-by: Yicheng Lu <[email protected]>
Co-authored-by: Yicheng Lu <[email protected]>
Signed-off-by: 400Ping <[email protected]>
rueian pushed a commit that referenced this pull request Nov 10, 2026
## Description

It is exactly the same issue as #63726.

So, tldr, we had a test helper, its goal is:
- Submit a job whose entrypoint is a shell script that writes its own
pid + loops printing `Waiting...`
- The helper makes sure when it returns, the shell is running. So that
all tests can safely assume the job is running
- The way it does is grepping the `Waiting...`

The issue is exactly the same issue as #63726. Before launching the
driver, the supervisor writes the entrypoint command into the job log,
and the command itself contains `echo 'Waiting...'`:

https://github.com/ray-project/ray/blob/fb7c757706aafd22025a2103268586cf138a143d/python/ray/dashboard/modules/job/job_supervisor.py#L186

So the grep matches before the shell has run a single line, the helper
returns. This causes the test to be flaky. This PR fixes it.

Signed-off-by: yicheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants