fix: gate read/write fd-cache fast paths on is_stale() (issue #30)#35
Merged
Conversation
The fd-cache fast paths served a cached descriptor without consulting staleness, while every other callback returns ESTALE on is_stale(). A foreign commit (epoch arm) or abort (is_branch_valid arm) could thus leave a held-open fd reading/writing a replaced or deleted backing file. Call is_stale() at the top of both fast paths so they ESTALE consistently with the rest of the filesystem. This still skips the resolve()/File::open() the cache exists to avoid. Signed-off-by: Cong Wang <cwang@multikernel.io>
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
is_stale()— the only 2 of 20 callbacks that didn't. A commit or abort from another mount could leave a held-open fd reading or writing a replaced/deleted backing file (issue High: stale/epoch protection is bypassed by file descriptor caches #30).is_stale()at the top of both fast paths so they returnESTALEconsistently with the rest of the filesystem, while still skipping theresolve()/File::open()the cache exists to avoid.is_stale()covers both failure modes: a foreign commit (epoch arm) and a foreign abort (branch-removal arm — abort signals throughis_branch_valid(), not the epoch, so no epoch bump was needed).Tests
fs::testsunit tests provingis_stale()is true after a foreign commit and after a foreign abort, and false when in sync.TTL=0,getattr/lookupalreadyESTALEbeforeread()is reached, so the read fast-path window is masked in normal operation. Verified the held-open-fd scenario returnsESTALEon both pre- and post-fix binaries, confirming the mask. This change is therefore defense-in-depth — it removes the lone inconsistency and stays correct if a read ever reaches the daemon without a precedinggetattr(read-ahead, future caching/TTL changes).Test Plan
cargo test --lib— 14 pass🤖 Generated with Claude Code