Skip to content

[core] Fix the Windows teardown error in the local:// working dir test - #66292

Merged
abrarsheikh merged 2 commits into
ray-project:masterfrom
YashwanthRanjanSingaravel:fix/local-working-dir-teardown
Sep 21, 2026
Merged

abrarsheikh merged 2 commits into
ray-project:masterfrom
YashwanthRanjanSingaravel:fix/local-working-dir-teardown

Conversation

@YashwanthRanjanSingaravel

@YashwanthRanjanSingaravel YashwanthRanjanSingaravel commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • TestLocalWorkingDir::test_used_in_place_without_upload[working_dir] passes, then errors at teardown.
  • On Windows the error is RecursionError: maximum recursion depth exceeded.
  • A local:// working_dir is used in place, so modify_context makes it the worker's cwd.
    • Windows refuses to remove a directory a live process sits in, giving WinError 32.
    • TemporaryDirectory's onerror handler then recurses until the stack runs out.
  • The test requested start_cluster before tmp_working_dir.
    • pytest tears fixtures down in reverse, so the directory went away while workers were alive.
  • Introduced by [core] Add local:// runtime_env URIs for code already in node #65245. It only shows in the soft failing flaky Windows postmerge job.

Changes

  • test_runtime_env_working_dir.py: request tmp_working_dir before start_cluster.
    • The cluster now tears down first.
    • Cluster.shutdown kills worker processes with wait=True, so the directory is free.
  • The docstring records why the fixture order matters.

Tests

  • No new test. The existing [working_dir] parameter is the regression test, and it is the failing one.
  • [py_modules] already passed, because that path only extends PYTHONPATH and never sets cwd.
  • The production behaviour is unchanged; test_directory_is_never_deleted still covers it.

@YashwanthRanjanSingaravel YashwanthRanjanSingaravel added the go add ONLY when ready to merge, run all tests label Sep 18, 2026
@YashwanthRanjanSingaravel
YashwanthRanjanSingaravel marked this pull request as ready for review September 18, 2026 19:52
@YashwanthRanjanSingaravel
YashwanthRanjanSingaravel requested a review from a team as a code owner September 18, 2026 19:52

@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 reorders the test fixtures in test_used_in_place_without_upload so that tmp_working_dir is requested before start_cluster. This ensures that pytest tears down the cluster before attempting to delete the temporary directory, preventing Windows file locking issues where a live worker process prevents directory removal. A detailed docstring explaining this behavior has also been added. There are no review comments to address.

@pytest.mark.parametrize("option", ["working_dir", "py_modules"])
def test_used_in_place_without_upload(
self, start_cluster, tmp_working_dir, option: str
self, tmp_working_dir, start_cluster, option: str

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering, even if we reverse the order, does cluster teardown necessarily mean the worker was removed? is it possible GCS and raylet tear down but worker only gets recycled later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I think you're right. I've switched the test to a tmp_path directory that teardown never has to remove, so the fix no longer depends on when workers get reaped.

@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Sep 19, 2026
@abrarsheikh
abrarsheikh merged commit c931968 into ray-project:master Sep 21, 2026
7 checks passed
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
ray-project#66292)

## Description

- `TestLocalWorkingDir::test_used_in_place_without_upload[working_dir]`
passes, then errors at teardown.
- On Windows the error is `RecursionError: maximum recursion depth
exceeded`.
- A `local://` working_dir is used in place, so `modify_context` makes
it the worker's cwd.
- Windows refuses to remove a directory a live process sits in, giving
`WinError 32`.
- `TemporaryDirectory`'s `onerror` handler then recurses until the stack
runs out.
- The test requested `start_cluster` before `tmp_working_dir`.
- pytest tears fixtures down in reverse, so the directory went away
while workers were alive.
- Introduced by ray-project#65245. It only shows in the soft failing flaky Windows
postmerge job.

## Changes

- `test_runtime_env_working_dir.py`: request `tmp_working_dir` before
`start_cluster`.
  - The cluster now tears down first.
- `Cluster.shutdown` kills worker processes with `wait=True`, so the
directory is free.
- The docstring records why the fixture order matters.

## Tests

- No new test. The existing `[working_dir]` parameter is the regression
test, and it is the failing one.
- `[py_modules]` already passed, because that path only extends
`PYTHONPATH` and never sets cwd.
- The production behaviour is unchanged;
`test_directory_is_never_deleted` still covers it.

---------

Signed-off-by: YashwanthRanjanSingaravel <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
ray-project#66292)

## Description

- `TestLocalWorkingDir::test_used_in_place_without_upload[working_dir]`
passes, then errors at teardown.
- On Windows the error is `RecursionError: maximum recursion depth
exceeded`.
- A `local://` working_dir is used in place, so `modify_context` makes
it the worker's cwd.
- Windows refuses to remove a directory a live process sits in, giving
`WinError 32`.
- `TemporaryDirectory`'s `onerror` handler then recurses until the stack
runs out.
- The test requested `start_cluster` before `tmp_working_dir`.
- pytest tears fixtures down in reverse, so the directory went away
while workers were alive.
- Introduced by ray-project#65245. It only shows in the soft failing flaky Windows
postmerge job.

## Changes

- `test_runtime_env_working_dir.py`: request `tmp_working_dir` before
`start_cluster`.
  - The cluster now tears down first.
- `Cluster.shutdown` kills worker processes with `wait=True`, so the
directory is free.
- The docstring records why the fixture order matters.

## Tests

- No new test. The existing `[working_dir]` parameter is the regression
test, and it is the failing one.
- `[py_modules]` already passed, because that path only extends
`PYTHONPATH` and never sets cwd.
- The production behaviour is unchanged;
`test_directory_is_never_deleted` still covers it.

---------

Signed-off-by: YashwanthRanjanSingaravel <[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.

3 participants