fix: weaken re-keyed child refs in rename to prevent mock leak - #417
Draft
toddr-bot wants to merge 1 commit into
Draft
fix: weaken re-keyed child refs in rename to prevent mock leak#417toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
When __rename re-keys directory children in %files_being_mocked, the new entries were stored as strong references. This prevented child mocks from being garbage collected when the user dropped their reference, causing the mock to persist and continue intercepting file operations indefinitely. Every other insertion point into %files_being_mocked already weakens the entry (new(), _new_link_for_broken_symlink(), _maybe_autovivify()); __rename was the sole omission.
This was referenced Jul 22, 2026
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.
What
Weaken
%files_being_mockedentries for children re-keyed during directory rename.Why
__renamewas the only insertion point into%files_being_mockedthat didn't weaken the entry. After renaming a directory, child mock objects could never be garbage collected — they persisted and continued intercepting file operations even after the user dropped their reference. Closes #416.How
Added
Scalar::Util::weaken()on the new hash entry at line 4103, matching the pattern used bynew(),_new_link_for_broken_symlink(), and_maybe_autovivify().Testing
Added two new subtests in
t/rename.tverifying that re-keyed entries are weakened and that child mocks are garbage collected after undef. Full suite: 1589 pass, 3 pre-existing fh-ref-leak.t failures.Quality Report
Changes: 2 files changed, 19 insertions(+)
Code scan: clean
Tests: failed (4 Failed, 94 test)
Branch hygiene: clean
Generated by Kōan