Repository navigation
Conversation
Since `bundler/inline` started installing gems in a forked subprocess, the child process fell off the end of the fork block, so it exited through the regular Ruby shutdown path and ran the script's `at_exit` handlers a second time (a minitest/autorun suite, for instance, ran once in the installer child and once in the script itself). A failing install in the child also printed a raw Ruby backtrace and the parent then called `exit` with its status, so a script that rescued `Bundler::BundlerError` around `gemfile` (which worked when installation happened in-process) never got the chance to handle it. The child now always ends with `exit!` after flushing its output, so no `at_exit` handlers run in it. Errors raised while installing are marshaled through a pipe and re-raised in the parent: Bundler errors are raised as the original class, other exceptions are wrapped in a `Bundler::InstallError` carrying the message, and a child that dies some other way raises a `Bundler::BundlerError` with its status. Since the child's backtrace is preserved, an unrescued error prints the same message and backtrace as before and exits with a non-zero status. Finally, the parent re-resolves the Gemfile after the child has installed the gems, which repeated the "Fetching gem metadata" and "Resolving dependencies..." output already printed by the child. That re-resolution is now silent. The non-fork code path, used on platforms without `Process.fork`, is unchanged.
Member
|
I merged #10048 instead, which fixes the same regressions and includes the specs from this PR. Please don't open pull requests as drafts and then leave them. |
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 was the end-user or developer problem that led to this PR?
Since
bundler/inlinestarted installing gems in a forked subprocess (4.1.0.beta), three regressions compared to 4.0.24 showed up:Process.forkblock, so it went through the normal Ruby shutdown and ran the script'sat_exithandlers a second time.ruby -e 'at_exit { puts "AT_EXIT #{$$}" }; require "bundler/inline"; gemfile(true, quiet: true) { source "https://rubygems.org"; gem "rake" }'printsAT_EXITtwice, and aminitest/autorunstyle script runs its whole suite inside the installer child.exit(status), sobegin; gemfile { ... }; rescue Bundler::BundlerError; end(which worked when installation happened in-process) never ran.What is your fix for the problem, implemented in this PR?
exit!(after flushing$stdout/$stderr), so noat_exithandlers run in it.Bundler::BundlerErrors are raised as their original class (with the child's backtrace preserved), other exceptions become aBundler::InstallErrorcarrying the message, and a child that dies some other way raises aBundler::BundlerErrorwith its status. An unrescued error therefore prints the same message/backtrace as before and exits non-zero, while scripts can rescue it again.The non-fork path (platforms without
Process.fork) is unchanged. Specs added for all three cases.Make sure the following tasks are checked