Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Load FileUtils before starting Bundler's worker threads - #10020

Merged
hsbt merged 1 commit into
ruby:masterfrom
linyiru:bundler-worker-load-fileutils
Nov 4, 2026
Merged

hsbt merged 1 commit into
ruby:masterfrom
linyiru:bundler-worker-load-fileutils

Conversation

@linyiru

@linyiru linyiru commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

What was the end-user or developer problem that led to this PR?

Since #10001 autoloads the vendored FileUtils, bundle install on TruffleRuby can fail intermittently:

NoMethodError: undefined method 'fu_list' for module Bundler::FileUtils
  lib/bundler/vendor/fileutils/lib/fileutils.rb:396:in 'Bundler::FileUtils#mkdir_p'
  lib/bundler/source/rubygems.rb:500:in 'block in Bundler::Source::Rubygems#fetch_gem'

It failed bin/rake dev:deps in this job on #10005, which doesn't touch FileUtils. The same job passed on master at e771d2c, so it depends on timing.

CRuby makes other threads wait for an autoload in progress. TruffleRuby 34.0.1 shows them the constant while its file is still loading, so a second worker can call mkdir_p (line 396) before fu_list (line 2485) exists. ParallelInstaller installs rake on the main thread first, which loads FileUtils there, so the first use only lands in the download workers when rake is already installed, as it is in this job.

What is your fix for the problem, implemented in this PR?

Require FileUtils at the start of Worker#create_threads, the only place in lib/bundler that starts a thread, so it has finished loading before any worker exists.

I chose this over a require at the top of worker.rb because definition.rb loads that file, which would bring FileUtils back on every require "bundler/setup" and undo #10001. The existing "does not load the vendored FileUtils" spec still passes.

Verification

With a sleep added to a copy of the vendored fileutils.rb to stretch the load, staggered jobs through a real Bundler::Worker on TruffleRuby 34.0.1 (arm64-darwin):

jobs that passed
Before 1 of 4, the other 3 raised the fu_list error above
After 4 of 4

I couldn't reproduce the failure through a full bundle install locally, even with the stretched load, so that path rests on this job in CI. JRuby wasn't tested.

The new spec fails without the change (expected: "true", got: "false").

Make sure the following tasks are checked

🤖 Generated with Claude Code

Autoloading the vendored FileUtils moved its first use into the gem
download workers whenever rake is already installed. CRuby makes other
threads wait for an autoload in progress, but TruffleRuby shows them the
constant while its file is still loading, so a second worker can call
mkdir_p before fu_list is defined:

    NoMethodError: undefined method 'fu_list' for module Bundler::FileUtils

Require it in Worker#create_threads, the one place Bundler starts threads.
worker.rb itself is loaded by definition.rb, so requiring it at the top of
that file would load FileUtils on every `require "bundler/setup"` again.
@hsbt
hsbt merged commit 1e8e87d into ruby:master Nov 4, 2026
114 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