fix: preserve open filehandle data when file is unlinked#391
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: preserve open filehandle data when file is unlinked#391Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
POSIX guarantees that open file descriptors survive unlink() — the file data remains accessible until all handles are closed. Previously, unlink() immediately cleared contents, causing reads on open handles to return EOF. Fix: before clearing contents, detach any open filehandles by giving them a strong reference to a private copy of the data. Handles then operate independently of the mock's "exists" state. 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.
What
Open filehandles now survive
unlink()— reads/writes continue working until close.Why
POSIX guarantees that open file descriptors survive unlink (data persists until all fds are closed). Previously,
unlink()immediately cleared{'contents'}on the mock object, causing any open handle to see EOF on read or lose data on write. This violated basic Unix semantics that many programs rely on (temp files, log rotation, etc.).How
Before clearing contents in
unlink(), detect active filehandles via the mock's{'fhs'}list. For each live handle, replace the weak data reference with a strong reference to a detached hashref containing the file contents. The handles then operate on their own private copy, independent of the mock's existence state.Testing
New
t/unlink_open_handle.twith 5 subtests:Full suite passes.
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 128 insertions(+)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline