bootsnap: Bootsnap causes kamal setup to hang in Ruby 3.3.5

I have a new Rails app, There are some env

ruby 3.3.5
rails 8.0.0
kamal 2.3.0

Dockerfile

# Install application gems
RUN bundle install
RUN rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
RUN rm -rf tmp/cache/bootsnap*
RUN bundle exec bootsnap precompile --gemfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

When I run kamal setup

 DEBUG [c688ef86]       #15 /bin/sh -c bundle install
 DEBUG [c688ef86]       #15 CACHED
 DEBUG [c688ef86]
 DEBUG [c688ef86]       #16 /bin/sh -c rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
 DEBUG [c688ef86]       #16 CACHED
 DEBUG [c688ef86]
 DEBUG [c688ef86]       #17 /bin/sh -c rm -rf tmp/cache/bootsnap*
 DEBUG [c688ef86]       #17 CACHED
 DEBUG [c688ef86]
 DEBUG [c688ef86]       #18 /bin/sh -c bundle exec bootsnap precompile --gemfile

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 31 (16 by maintainers)

Commits related to this issue

Most upvoted comments

This solves the issue for me.

Probably because bootsnap terminated too early; it hasn’t frozen yet. There is something wrong with Process.fork, it seems the first fork is fine but the subsequent forks seem to hang.

POC code:

$stdout.sync = true
pid_list = 4.times.map do
  Process.fork do
    puts 'forked success!'
    exit!(true)
  end
end

pid_list.each do |pid|
  Process.wait2(pid)
end

-j 0 and -j 1 won’t trigger the issue, we can use them in the meantime.

Switching to Ruby 3.2.6 fixes it for me too

I’ve published a 1.18.5 that tries to automatically detect this QEMU bug and when it does it disable parallel compilation.

It’s of course gonna be slower, but at least it will complete.

Thanks @midnight-wonderer for the initial version of the detection code.

I have been able to get my builds to run past bootsnap precompile with the following setting:

Image

Use Rosetta for x86_64/amd64 emulation on Apple Silicon specifically.

Here is my second shot but this time just the detection logic. #497

Try with:

gem ‘bootsnap’, require: false, git: ‘https://github.com/midnight-wonderer/ruby-bootsnap.git’, branch: ‘bug/test-forks-before-usage’

Good job @midnight-wonderer , confirming it works with ruby 3.3.7

no hanging at

RUN bundle install --verbose && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
    bundle exec bootsnap precompile --gemfile

for simple

docker buildx build --push --platform linux/arm64,linux/amd64 -t your-repo/project-name .

edit: works even with ruby 3.4.2

Here is my second shot but this time just the detection logic. https://github.com/Shopify/bootsnap/pull/497

Try with:

gem 'bootsnap', require: false,
  git: 'https://github.com/midnight-wonderer/ruby-bootsnap.git',
  branch: 'bug/test-forks-before-usage'

bootsnap works when using Rosetta.

So that confirms my suspicion that Ruby is running into some QEMU limitation.

I just thought of something. For people who manage to make it hang in local, if you can try to enter the container from another shell, and kill the ruby process with kill -S ABRT -p <PID>.

That should hopefully cause Ruby to crash and print a crash report with a backtrace. Short of having a proper repro, that may give clues as to where it’s stuck.

Also stuck on ruby 3.3.7. and latest bootsnap release.

With the --verbose flag it shows paths being processed, then at some point it just stops outputting. The order of the file paths is not deterministic, so it is hard to pinpoint anything specific.

While it says here https://github.com/rails/rails/issues/54039, that the issue is with arm64, I am using amd64 and still getting stuck:

docker buildx build --push --platform linux/amd64 --builder kamal-local-docker-container -t kitschmaster/eternal:... -t kitschmaster/eternal:latest --label service="eternal" --file Dockerfile .

I changed ruby version to 3.2.5. bootsnap precompile is ok!