Skip to content

Don't set BUNDLER_ORIG environment variables#6052

Closed
peterzhu2118 wants to merge 1 commit into
ruby:masterfrom
peterzhu2118:dont-create-env-vars
Closed

Don't set BUNDLER_ORIG environment variables#6052
peterzhu2118 wants to merge 1 commit into
ruby:masterfrom
peterzhu2118:dont-create-env-vars

Conversation

@peterzhu2118

Copy link
Copy Markdown
Member

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

Bundler creates a backup of environment variables by creating new environment variables prefixed with BUNDLER_ORIG_. This caused Ruby test suite's environment variable leak checker to report lots of created/changed environment variables (suppressed in commit ruby/ruby@6d83590).

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

This PR stops creating BUNDLER_ORIG_ environment variables and instead relies on storing backups inside Ruby at boot.

However, this implementation causes a breaking change when spawning child processes. For example:

require "bundler"

ENV["BUNDLE_BIN_PATH"] = "foobar"

script = <<~RUBY
  require "bundler"

  Bundler.with_original_env do
    p ENV["BUNDLE_BIN_PATH"]
  end
RUBY

puts `bundle exec ruby -e '#{script}'`

Before this change it outputs nil while after this change it outputs "foobar".

Make sure the following tasks are checked

@hsbt

hsbt commented Jun 16, 2026

Copy link
Copy Markdown
Member

👋 Dropping the BUNDLER_ORIG_* vars breaks the cross-process semantics of with_original_env/with_unbundled_env (your own example shows it).

Since this is really about quieting the test helper's env-leak checker, and ruby/ruby has lived fine with the suppression for ~4 years, the compatibility cost feels too steep.

Closing it, but thanks for your investigation.

@hsbt hsbt closed this Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants