fix: prevent filehandle reference leak in stat override#25
Merged
atoomic merged 1 commit intocpanel:masterfrom Feb 22, 2026
Merged
fix: prevent filehandle reference leak in stat override#25atoomic merged 1 commit intocpanel:masterfrom
atoomic merged 1 commit intocpanel:masterfrom
Conversation
_check() stored the file argument in $_last_call_for for -X _ caching. When the argument was a filehandle reference (not a string path), this prevented the filehandle from being garbage collected, keeping the underlying file descriptor open. This caused "spooky action-at-a-distance" bugs: e.g. a socketpair read hanging because a dup'd write-end filehandle was kept alive by the leaked reference, even after leaving scope. Fix: only cache string filenames in $_last_call_for, not references. Ref: cpanel/Test-MockFile#179 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 22, 2026
atoomic
approved these changes
Feb 22, 2026
Koan-Bot
added a commit
to atoomic/Test-MockFile
that referenced
this pull request
Feb 26, 2026
- Remove .claude/worktrees/ submodule entry from tracking - Add .claude/ to .gitignore - Remove SKIP wrapper from socketpair test — Overload::FileCheck fix (cpanel/Overload-FileCheck#25) is now released Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Koan-Bot
added a commit
to atoomic/Test-MockFile
that referenced
this pull request
Feb 26, 2026
- Remove .claude/worktrees/ submodule entry from tracking - Add .claude/ to .gitignore - Remove SKIP wrapper from socketpair test — Overload::FileCheck fix (cpanel/Overload-FileCheck#25) is now released Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
atoomic
pushed a commit
to cpanel/Test-MockFile
that referenced
this pull request
Feb 26, 2026
- Remove .claude/worktrees/ submodule entry from tracking - Add .claude/ to .gitignore - Remove SKIP wrapper from socketpair test — Overload::FileCheck fix (cpanel/Overload-FileCheck#25) is now released Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
$_last_call_forin_check()to only cache string filenames, not filehandle referencesRoot Cause
_check()stored its$fileargument in$_last_call_forfor-X _caching support. When the argument was a filehandle reference (e.g. from-S $fh), this prevented the filehandle from being garbage collected, keeping the underlying file descriptor open.This caused "spooky action-at-a-distance" bugs: a socketpair read could hang because a dup'd write-end filehandle was kept alive by the leaked reference.
Fix
Only string filenames are cached. Filehandle references pass through without being retained.
Test plan
t/fh-ref-leak.tverifies filehandles are GC'd after file checks-X _tests still pass (string filename caching preserved)Ref: cpanel/Test-MockFile#179
🤖 Generated with Claude Code