Project

General

Profile

Bug #18567

Updated by Eregon (Benoit Daloze) almost 3 years ago

CRuby over time moves more and more code to default gems, to bundled gems and or even stops shipping some gems which used to be stdlibs (#5481). 
 I believe the main motivation for that is being to fix security issues without needing to make a CRuby release, and that makes sense. 

 There are however multiple unwanted side effects of this: 

 1. Removing gems from stdlib (e.g., #17873) is a breaking change, which makes upgrading to a new Ruby version more difficult. 
    I think this should only be done if there is a clear gain. 
    Being a default gem is already enough to fix a security issue without a CRuby release. 
 2. When any gem depends on a default gem, it tends to break on all Ruby implementations except CRuby, and for older Ruby versions. 

 Let's focus on this second point. 
 There can be good reasons to depend on a specific version (or ~>/>=) of a default gem, for instance to ensure a given security issue is addressed. 
 In other cases, I think there is no value to depend explicitly on a default gem, it would work without an explicit dependency since it is still "in stdlib". 

 And it is actually harmful to depend on default gems for JRuby, TruffleRuby and older Ruby versions, because the default gem does typically not work there yet, but the stdlib works just fine! 
 The reason for that is simple, those gems used to be stdlib and so were implemented directly in the Ruby implementation. 

 Also depending on default gem will typically be redundant with what's in stdlib, which is then a waste of network, time and disk. 

 For larger default gems (e.g., openssl), I believe the solution is those gems to support JRuby, TruffleRuby, etc. 
 This is useful so the behavior for a given version of the gem is compatible between Ruby implementations, has the same security fixes, etc. 
 It is however a large effort and overhead to do this, and it only makes sense if people are going to need to depend on such a gem explicitly (either for security or new features in a given version), otherwise the version in stdlib is good enough and much simpler. 

 Here are I think some clear cases of default gems which are clearly more overhead than what they gain: 
 * io-wait: just a few methods very tight to IO internals, should really be core 
 * io-nonblock just a few methods very tight to IO internals, should really be core 
 * digest: has a public header and so versioning it doesn't work. Also it makes sense to reuse e.g. MessageDigest on JVM for better performance. 

 These are all small, they are all fairly stable, and it's unclear why they are even default gems in the first place. 
 They also seem fairly unlikely to have security issues. 

 So this is what I propose: 
 * Do not depend on default gems unless necessary (for security or feature), or unless we know the next version of Ruby will no longer ship that gem. An example is `net-protocol` depending needlessly on `io-wait`, `net-protocol`, I'll make a PR for that. 
 * I think `io-wait`, `io-nonblock` and `digest` should no longer be default gems in the future to clarify the situation. The first two should be core, `digest` should be regular stdlib.

Back