damccorm opened a new pull request, #41868:
URL: https://github.com/apache/beam/pull/41868
Note: this PR was auto-generated by tooling. Before moving it out of draft,
the author has done a full review of the PR, specifically evaluating it on the
following criteria:
- The PR is an appropriate fix for the issue (e.g. we're not changing a test
to avoid a bug)
- The PR is a simple fix to the issue (e.g. we're not adding infra when we
could just modify a test)
- The PR is not covering for other problems (e.g. if we're bumping timeouts,
it is not because we're covering for a performance problem)
Full details of the methodology of generation and review can be found here -
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to
generate this, please comment below - they will be addressed by the author not
the tooling :)
## Summary
Fixes intermittent Windows `PermissionError: [Errno 13] Permission denied`
failures when `MultiProcessShared` opens a `.address` (or `.address.error`)
file immediately after a spawned server process publishes it with `os.rename()`.
## Failing Run
- **Workflow**: `Python tests` — `Python Unit Tests (windows-latest, 3.14,
py314)`
- **Run**: https://github.com/apache/beam/actions/runs/46774372052 (job
https://github.com/apache/beam/actions/runs/46774372052/job/143095880917, 1
failed / 7744 passed)
- **Failing Test**:
`apache_beam/ml/inference/base_test.py::RunInferenceBaseTest::test_run_inference_loads_different_models_multi_process_shared`
- **Error**: `PermissionError: [Errno 13] Permission denied:
'D:\\a\\beam\\beam\\sdks\\python\\target\\.tox\\py314-win\\tmp\\954f04c862704dec82455bd64aff177a_model_status.address'`
at `sdks/python/apache_beam/utils/multi_process_shared.py:420`
## Root Cause
1. In `_run_server_process()`, the spawned child (PID 9684) logged `Proxy
serving 954f04c862704dec82455bd64aff177a_model_status at ('127.0.0.1', 51350)`,
wrote `address_file + '.tmp'`, closed it, and ran `os.rename(address_file +
'.tmp', address_file)` (`multi_process_shared.py:323-325`). No
`cleanup_files()` exit occurred.
2. In `_create_server()` / `_get_manager()`, the parent held both
`_process_local_lock` and `self._cross_process_lock` on that fresh UUID tag,
polled `os.path.exists(address_file)` (`multi_process_shared.py:557`), and
immediately called `open(address_file)` (`multi_process_shared.py:420`).
3. On Windows, `os.path.exists()` (`GetFileAttributesExW`) can observe the
renamed entry before `MoveFileW` finishes closing its `DELETE`-access handle or
while a Windows filesystem minifilter (e.g., Windows Defender real-time scan)
holds a transient handle on the newly renamed file. Because CPython's `open()`
uses CRT `_wsopen_s` without `FILE_SHARE_DELETE`, the resulting
`ERROR_SHARING_VIOLATION` / `ERROR_ACCESS_DENIED` maps to `EACCES`
(`PermissionError`).
4. The same `os.rename()` → `os.path.exists()` → `open()` handoff applies to
`error_file` (`multi_process_shared.py:334`, `561`).
## Changes
- `sdks/python/apache_beam/utils/multi_process_shared.py`:
- Added `_is_windows()`, `_is_windows_permission_error()`, and
`_read_published_file(path, with_stat=False)` decorated with
`@retry.with_exponential_backoff(num_retries=5, initial_delay_secs=0.05,
retry_filter=_is_windows_permission_error)` (~1.55s expected total retry budget
on Windows; zero retries on POSIX or for non-`PermissionError` exceptions).
- Used `_read_published_file()` when reading `address_file` in
`_get_manager()` and `error_file` in `_create_server()`.
- `sdks/python/apache_beam/utils/multi_process_shared_test.py`:
- Added 5 unit tests covering Windows transient `PermissionError`
recovery, POSIX non-retry, retry exhaustion, `FileNotFoundError` non-retry, and
end-to-end `MultiProcessShared.acquire()` recovery.
## Verification
- Verified syntax (`python3 -m py_compile`) and 80-char line limit locally.
- Executed the 4 `_read_published_file` unit tests (`4/4` passed in
`0.010s`) plus an in-process `MultiProcessShared.acquire()` retry test
(`calls=3`, passed) locally with minimal stubs for `fasteners` / `pickler`.
- `Python tests` (including `windows-latest` Python 3.14) and `PreCommit
Python Formatter` run automatically on this PR.
### Verification
- Triggered `.github/workflows/python_tests.yml` workflow run on branch:
[`46786793044`](https://github.com/apache/beam/actions/runs/46786793044)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]