Skip to content

test(compat): close the persistent runner's stderr handle on cleanup - #11466

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:fix/11363-runner-stderr-handle
Nov 30, 2026
Merged

Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:fix/11363-runner-stderr-handle

Conversation

@vaibhavdabas16

@vaibhavdabas16 vaibhavdabas16 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11363.

VenvExecutor._ensure_subprocess opened .runner_stderr.log for 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 makes shutil.rmtree fail with PermissionError: [WinError 32].
  • Restarting a crashed runner, or a Popen that raised, left the handle open.

Changes:

  • The log is opened in a with block around Popen, so the parent's handle is closed as soon as Popen returns or raises. The child keeps its own copy, and _recent_stderr() / _last_panic() already read the log by path.
  • When graceful shutdown times out, cleanup() now calls wait() after kill(), so the runner no longer holds the log when rmtree() starts.

Tests: in test_venv_manager.py, using a fake Popen, 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 order terminate, wait, kill, wait.
  • test_runner_stderr_handle_is_closed_when_startup_fails: Popen raises FileNotFoundError, 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.py gives 14 passed. ruff and ruff-format pass via pre-commit.

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings chore labels Nov 25, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 25, 2026
Xuanwo
Xuanwo previously requested changes Nov 25, 2026

@Xuanwo Xuanwo left a comment

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.

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.
@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Thanks @Xuanwo, both done in 8ad8a5c:

  • open() is now scoped to the Popen call with a with block, so the parent's handle closes even when Popen raises. Since nothing holds it any more, I dropped _stderr_file.
  • cleanup() calls wait() after kill(), before rmtree().

New tests cover a startup failure (Popen raises FileNotFoundError and the file handed to it ends up closed) and a graceful-shutdown timeout (call order terminate, wait, kill, wait).

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 25, 2026

@Xuanwo Xuanwo left a comment

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.

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.

@Xuanwo
Xuanwo dismissed their stale review November 25, 2026 07:15

Verified failed startup and child termination before directory removal at 8ad8a5c: #11466 (review)

@lance-gatekeeper lance-gatekeeper 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.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 25, 2026
@Xuanwo
Xuanwo merged commit 712e8d8 into lance-format:main Nov 30, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings chore K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The persistent runner leaves its stderr file handle open after cleanup

2 participants