Skip to content

Lock the current store file and close failed acquisition handles - #62

Merged
nobu merged 4 commits into
ruby:masterfrom
OskarEichler:codex/close-failed-lock-descriptors
Sep 5, 2026
Merged

Lock the current store file and close failed acquisition handles#62
nobu merged 4 commits into
ruby:masterfrom
OskarEichler:codex/close-failed-lock-descriptors

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

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.

  • External focused corpus: 8 cleanup checks plus deterministic and concurrent writer cases verified on this isolated branch under rbenv Ruby 4.0.6.
  • Existing upstream RBENV_VERSION=4.0.6 rbenv exec rake test: 13 tests / 26 assertions, zero failures before and after.
  • All files and injected failures are confined to scratch storage; no production operations.
  • No repository tests added or modified under the contributor's task constraint. Other Ruby versions and native Windows were not executed locally.

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.

@nobu
nobu merged commit dfa3b27 into ruby:master Sep 5, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants