Lock the current store file and close failed acquisition handles - #62
Merged
nobu merged 4 commits intoSep 5, 2026
Merged
Conversation
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
Acquire a lock on the current store inode, retrying if an atomic save replaced it while acquisition was pending. Close abandoned/failed handles through ensure. This also closes write-mode descriptors on flock failure.
Reproduction and verification
A deterministic writer opened the old inode, paused before flock, then resumed after another writer atomically replaced the file. Two increments previously produced 1; this patch produces 2. A bounded five-writer/100-update run ended at 23 with atomic writers and 28 with mixed writers on the original, versus 100 for fast/atomic/mixed modes after this patch. IOError/Interrupt lock fixtures also preserve exceptions and close their handles.
RBENV_VERSION=4.0.6 rbenv exec rake test: 13 tests / 26 assertions, zero failures before and after.Breaking-change notes and limitations
The inode check adds filesystem work to every successful acquisition, including fast mode, because another cooperating writer may use atomic mode. Randomized paired local benchmark (11 measured samples after two warmups, 500 transactions each): cleanup-only consumer 12.057ms fast / 69.504ms atomic; inode-retry variant 13.116ms / 72.145ms. The consumer audit has therefore withheld the inode-retry portion under its performance policy; descriptor cleanup alone is adopted. No speed improvement is claimed. Native Windows, NFS and mixed old/new implementations are not verified; same-path cooperating patched writers were tested.