[fix] Ensure that jruby-rack leaves ENV vars and Gem.path in consistent state #23
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.
As noted at jruby/warbler#575 for warbler, it is similarly possible for jruby-rack to leave ENV['GEM_PATH'] and Gem.path in an inconsistent state after it updates them. This would make any later Gem.clear_paths or Bundler usage (driven from the ENV vars) unpredictable.
This happens because jruby-rack alters
ENV['GEM_PATH']``, in some cases but does not force Rubygems to recalculate Gem.paths. Normally this is fine, however if Gem.paths had already been used and cached prior to this manglingGem.pathwill contain a "stale" value with respect to ENV. (e.g possibly missing theGEM_HOME/Gem.default_dirvalue, or retaining values from an oldGEM_PATH`. Clearing the paths is the only way to ensure things are consistent for later usage.In particular this currently can happen on JRuby 9.4+ because often
Gem.pathis already initialized by the time we boot, due to the use of default gems such asstringio. Rather than assume a given state, it would be better to ensure it is consistent by clearing paths whenever we touchENV['GEM_PATH'].