ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Fix Namespace RubyGems isolation issue

Open jsxs0 opened this issue 7 months ago • 5 comments

Ensure independent RubyGems environments per namespace

This fix resolves an issue where the Namespace feature fails to properly isolate RubyGems state. In the current implementation, RubyGems gets loaded into the root namespace and is shared across all user namespaces. This causes gem versions loaded in one namespace to affect others, leading to Gem::LoadError problems.

The fix explicitly removes any inherited Gem constant during main namespace and newly created namespace initialisation, then loads a fresh RubyGems environment in each namespace. This allows each namespace to manage its own gem dependencies without conflicts between namespaces.

Fixes Bug #21324.

jsxs0 avatar May 13 '25 06:05 jsxs0

Couldn't these be extracted as a function?

nobu avatar May 13 '25 09:05 nobu

The created namespace is copied from the root namespace, so we need to check if the Gem exists in the root namespace. The way to do it is... hmm, accessing RCLASSEXT_CONST_TBL(RCLASS_EXT_PRIME(rb_cObject)) is the only way for now. It might be good to add a function to do that specifically.

tagomoris avatar May 13 '25 10:05 tagomoris

Do we need to load RubyGems explicitly in new Namespace if present in root one?

simi avatar May 13 '25 11:05 simi

I'm not familiar to RubyGems itself, but it seems better to clear RubyGems's internal status than to remove-and-require rubygems. And I guess this code doesn't work well because the .rb files of rubygems are already included in $LOADED_FEATURES.

tagomoris avatar May 13 '25 11:05 tagomoris

It's not a correct fix, see https://bugs.ruby-lang.org/issues/21324#note-6

eregon avatar May 13 '25 11:05 eregon