Repository navigation
Conversation
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves intermittent PermissionError (EACCES) failures on Windows when reading newly renamed .address and .address.error files in MultiProcessShared by introducing a Windows-scoped exponential backoff retry helper (_read_published_file). The root cause analysis is thorough, the retry parameters are well-bounded (~1.55s max budget on Windows, zero overhead on POSIX), and the accompanying unit tests comprehensively cover retry recovery, exhaustion, platform filtering, and exception filtering.
🔍 General Feedback
- The implementation and unit tests in
multi_process_shared.pyandmulti_process_shared_test.pylook solid and ready to merge. - Minor optional follow-up: in
multi_process_shared_test.py(test_reused_server_address_resets_stale_proxy_connection, around line 765),addr2_fileis read via rawopen(addr2_file)immediately afterhandle2._create_server(addr2_file), which could also benefit frommulti_process_shared._read_published_file(addr2_file)on Windows CI.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Addressed in commit
Note: the /gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR adds a @retry.with_exponential_backoff-decorated _read_published_file helper to handle transient Windows PermissionError exceptions when reading .address and .address.error files immediately after os.rename(). The implementation is clean, properly scoped to win32 and PermissionError, and well-covered by unit tests.
🔍 General Feedback
- Preserving
os.fstat(fin.fileno())inside the open context manager whenwith_stat=Trueensures file identity checks forserver_keyremain atomic with reading the address. - All call sites reading published address/error files (including
addr2_fileinmulti_process_shared_test.py) now consistently use_read_published_file.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41868 +/- ##
=========================================
Coverage 58.16% 58.16%
Complexity 2848 2848
=========================================
Files 1211 1211
Lines 173645 173654 +9
Branches 2330 2330
=========================================
+ Hits 101005 101014 +9
Misses 69925 69925
Partials 2715 2715
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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:
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 deniedfailures whenMultiProcessSharedopens a.address(or.address.error) file immediately after a spawned server process publishes it withos.rename().Failing Run
Python tests—Python Unit Tests (windows-latest, 3.14, py314)apache_beam/ml/inference/base_test.py::RunInferenceBaseTest::test_run_inference_loads_different_models_multi_process_sharedPermissionError: [Errno 13] Permission denied: 'D:\\a\\beam\\beam\\sdks\\python\\target\\.tox\\py314-win\\tmp\\954f04c862704dec82455bd64aff177a_model_status.address'atsdks/python/apache_beam/utils/multi_process_shared.py:420Root Cause
_run_server_process(), the spawned child (PID 9684) loggedProxy serving 954f04c862704dec82455bd64aff177a_model_status at ('127.0.0.1', 51350), wroteaddress_file + '.tmp', closed it, and ranos.rename(address_file + '.tmp', address_file)(multi_process_shared.py:323-325). Nocleanup_files()exit occurred._create_server()/_get_manager(), the parent held both_process_local_lockandself._cross_process_lockon that fresh UUID tag, polledos.path.exists(address_file)(multi_process_shared.py:557), and immediately calledopen(address_file)(multi_process_shared.py:420).os.path.exists()(GetFileAttributesExW) can observe the renamed entry beforeMoveFileWfinishes closing itsDELETE-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'sopen()uses CRT_wsopen_swithoutFILE_SHARE_DELETE, the resultingERROR_SHARING_VIOLATION/ERROR_ACCESS_DENIEDmaps toEACCES(PermissionError).os.rename()→os.path.exists()→open()handoff applies toerror_file(multi_process_shared.py:334,561).Changes
sdks/python/apache_beam/utils/multi_process_shared.py:_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-PermissionErrorexceptions)._read_published_file()when readingaddress_filein_get_manager()anderror_filein_create_server().sdks/python/apache_beam/utils/multi_process_shared_test.py:PermissionErrorrecovery, POSIX non-retry, retry exhaustion,FileNotFoundErrornon-retry, and end-to-endMultiProcessShared.acquire()recovery.Verification
python3 -m py_compile) and 80-char line limit locally._read_published_fileunit tests (4/4passed in0.010s) plus an in-processMultiProcessShared.acquire()retry test (calls=3, passed) locally with minimal stubs forfasteners/pickler.Python tests(includingwindows-latestPython 3.14) andPreCommit Python Formatterrun automatically on this PR.Verification
.github/workflows/python_tests.ymlworkflow run on branch:46786793044