Repository navigation
vm: release the flock when #close_read or #close_write closes the stream - #981
Merged
Merged
Conversation
close the whole stream, as rb_io_close_read and rb_io_close_write do, but never released the descriptor File#flock holds, which #close does. The lock outlived the stream, so a later blocking flock on the same file waited forever. Each place these two methods set `closed` now calls releaseLockFd, as close(2) on MRI's descriptor drops its flock. Measured with rubydiff against MRI 4.0.7 (arm64-darwin25): the issue's program timed out after 30 s on rbgo where MRI answers [[:after_close_read, 0], [:after_close_write, 0]] in 95 ms; with every lock LOCK_NB, rbgo answered [false, false, false, true, true] where MRI answers [0, 0, 0, true, true]. Both agree now. TestCloseHalfReleasesTheFlock holds the LOCK_NB program, so a regression fails instead of hanging. Fixes #979 Co-Authored-By: Claude Opus 5.5 <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
#close_readon a read-onlyFileand#close_writeon a write-only one close the whole stream, asrb_io_close_read/rb_io_close_writedo. But they never released the descriptorFile#flockholds, which#closedoes. The lock outlived the stream, and a later blockingflockon the same file waited forever.Each place these two methods set
closednow callsreleaseLockFd, asclose(2)on MRI's descriptor drops its flock. That covers the non-duplex path and the duplex path once both halves are shut.Measured
rubydiffagainst MRI 4.0.7 (arm64-darwin25).[[:after_close_read, 0], [:after_close_write, 0]]in 95 ms. They agree now.LOCK_NB: rbgo answered[false, false, false, true, true], MRI[0, 0, 0, true, true]. They agree now.TestCloseHalfReleasesTheFlockholds theLOCK_NBprogram with MRI's output as its expected value, so a regression fails instead of hanging. It skips Windows, wasm and plan9, which have noflock(2).go test ./...passed (internal/vm249 s). After the rebase, the flock, pin and opened-file tests pass. The full suite was not re-run locally at a load average of ~180; CI runs it.buildscan --vetpassed under all 19 CI configurations.Fixes #979
Refs #978 (merged; this branch is rebased onto it, which also releases its inode pin at these four places)
🤖 Generated with Claude Code