Skip to content

Close the Dirs created by Dir.for_fd in test_for_fd - #3191

Open
hsbt wants to merge 1 commit into
ruby:masterfrom
hsbt:claude/cranky-lichterman-e55e1f
Open

hsbt wants to merge 1 commit into
ruby:masterfrom
hsbt:claude/cranky-lichterman-e55e1f

Conversation

@hsbt

@hsbt hsbt commented Oct 1, 2026

Copy link
Copy Markdown
Member

FileTestSingletonTest started failing with Errno::EBADF: Bad file descriptor @ fptr_finalize_flush in ruby/ruby's test-bundled-gems on macOS. The cause is DirSingletonTest#test_for_fd, which runs before it.

Dir.for_fd takes ownership of the descriptor, but the test passed dir.fileno and never closed the returned Dirs. After dir was closed, two unclosed Dirs still owned the same number. When GC finalized them, closedir closed whatever file had reused that number.

This gives each call a fresh descriptor from IO.sysopen and closes the returned Dir. I confirmed locally that no Dir owning the old descriptor remains after the test.

https://github.com/ruby/ruby/actions/runs/36829284827

Generated with Claude Code

Dir.for_fd takes ownership of the descriptor, so passing dir.fileno left two unclosed Dirs owning the same fd once dir was closed. Their finalizers later closed whatever file reused that number, which made FileTestSingletonTest fail with Errno::EBADF on ruby/ruby's macOS CI. Give each call its own descriptor and close the returned Dir.

https://github.com/ruby/ruby/actions/runs/36829284827

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant