Fix flaky DirSingletonTest GC failures in test_fchdir and test_for_fd#3004
Merged
Conversation
The Dir created by `Dir.new(Dir.pwd).fileno` was only referenced long enough to read its fileno, so it became collectable immediately. When GC ran between the assert_send_type calls the fd was closed, making the later `Dir.fchdir(fd)` fail with Errno::EBADF. Keep the Dir in a local and close it in ensure. Surfaced on ruby/ruby ZJIT CI with --enable-zjit=dev --zjit-call-threshold=1. https://github.com/ruby/ruby/actions/runs/27735384476/job/82051097840 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
test_for_fd has the same pattern as test_fchdir: the Dir from `Dir.new(Dir.pwd).fileno` is collectable before `Dir.for_fd(fd)` runs, so an ill-timed GC closes the fd and the call fails with Errno::EBADF. Keep the Dir alive in a local and close it in ensure. Co-Authored-By: Claude Opus 4.8 <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.
The
Dircreated byDir.new(Dir.pwd).filenointest_fchdirandtest_for_fdwas only referenced long enough to read its fileno, so it became collectable right away. When GC ran before the descriptor was used it got closed, making the laterDir.fchdir(fd)andDir.for_fd(fd)calls fail withErrno::EBADF.This surfaced on
ruby/rubyZJIT CI runningmake test-bundled-gemswith--enable-zjit=dev --zjit-call-threshold=1, where allocation and GC timing shifted enough to expose it. Keep the Dir in a local and close it in ensure so the descriptor stays valid for the whole test.https://github.com/ruby/ruby/actions/runs/27735384476/job/82051097840