Repository navigation
test(compat): close the persistent runner's stderr handle on cleanup - #11466
Conversation
VenvExecutor opened a stderr log for the persistent runner but never closed it. Cleanup left the descriptor open, and on Windows the open file made removing the venv fail. Restarting a crashed runner also leaked the previous handle. Close the handle in cleanup before the venv is removed, and before opening a new one for a restarted runner. Fixes lance-format#11363
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks for fixing normal cleanup and restart. On Linux, forcing Popen to raise FileNotFoundError still left .runner_stderr.log open in the parent. Please scope open() to the Popen call with a with block. The child keeps its own handle, and _recent_stderr() already reads by path. A startup-failure test can capture the file passed to Popen and assert it is closed after the exception.
Please also wait() after a successful kill() before calling rmtree(). A runner that times out during graceful shutdown can still hold the log when directory removal starts.
Open the stderr log in a with block around Popen, so the parent's handle is closed even when Popen raises. The child keeps its own copy and the log is read back by path. Wait for the runner after kill() so it no longer holds the log when the venv is removed.
|
Thanks @Xuanwo, both done in 8ad8a5c:
New tests cover a startup failure ( |
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks @vaibhavdabas16. On Linux, starting with a missing interpreter left the parent’s log descriptor open at 73beec15e and closed it at 8ad8a5c87. After a successful start, only the child held the log. I also forced a real runner through the kill path and verified it had been reaped before rmtree started. All 14 tests in the venv manager module passed. Both findings are resolved.
Verified failed startup and child termination before directory removal at 8ad8a5c: #11466 (review)
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The follow-up fixes address the startup-failure leak and ensure forced shutdown reaps the runner before directory removal. The child retains usable stderr, and cleanup remains idempotent. No blocking issues found.
Fixes #11363.
VenvExecutor._ensure_subprocessopened.runner_stderr.logfor the persistent compat runner and kept the handle in the parent, and nothing ever closed it:cleanup()removed the venv while the handle was still open. On Windows, that makesshutil.rmtreefail withPermissionError: [WinError 32].Popenthat raised, left the handle open.Changes:
withblock aroundPopen, so the parent's handle is closed as soon asPopenreturns or raises. The child keeps its own copy, and_recent_stderr()/_last_panic()already read the log by path.cleanup()now callswait()afterkill(), so the runner no longer holds the log whenrmtree()starts.Tests: in
test_venv_manager.py, using a fakePopen, so no venv or pylance install is needed.test_runner_stderr_handle_is_closed_in_the_parent[False/True]: the parent's handle is closed after start, and cleanup removes the venv and is idempotent. For a runner whose graceful wait times out, it checks the call orderterminate, wait, kill, wait.test_runner_stderr_handle_is_closed_when_startup_fails:PopenraisesFileNotFoundError, and the file handed to it is closed.All three fail against the previous version of this branch and pass now.
pytest python/tests/compat/test_venv_manager.pygives 14 passed. ruff and ruff-format pass via pre-commit.