fix(local-env): use context manager in _update_cwd to prevent fd leak - #8112
Closed
chinadbo wants to merge 2 commits into
Closed
fix(local-env): use context manager in _update_cwd to prevent fd leak#8112chinadbo wants to merge 2 commits into
chinadbo wants to merge 2 commits into
Conversation
Collaborator
|
Likely duplicate of #15552 — same root cause: bare open().read() fd leak in LocalEnvironment._update_cwd. |
chinadbo
force-pushed
the
fix/local-env-file-handle-leak
branch
from
April 27, 2026 13:18
5093488 to
8b54bcc
Compare
open(self._cwd_file).read().strip() leaks the file descriptor because the handle is never closed. Replace with a context manager to ensure prompt cleanup.
- Assert __exit__ is called in context manager test - Add test verifying fd is closed when f.read() raises UnicodeDecodeError
chinadbo
force-pushed
the
fix/local-env-file-handle-leak
branch
from
April 28, 2026 02:04
8b54bcc to
5ac130d
Compare
Contributor
|
Thanks for this contribution, @chinadbo! This is an automated hermes-sweeper review. The fix you proposed has already landed on
Closing as implemented on main. The additional tests in this PR ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
open(self._cwd_file).read().strip()in_update_cwdleaks the file descriptor because the handle is never explicitly closedwithstatement context manager to ensure prompt cleanup after each readTest plan
test_update_cwd_uses_context_manager— verifiesopen()is used with__enter__/__exit__(context manager)test_update_cwd_closes_file_handle— verifies no fd leak over 50 repeated callstest_local_env_blocklist.pyandtest_local_tempdir.pystill pass (21/21)