`gem install` crashes with `Gem::DependencyError: Unresolved dependency found during sorting` when a transitive gem pulls in a prerelease shared with a non-prerelease dependency

Aperta
#10,085 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
backend, devtools

Direzione di ricerca

Start with lib/rubygems/request_set.rb:537, where Gem::RequestSet#tsort_each_child rejects the resolved prerelease dependency; compare its matching check with the prerelease handling described for Gem::Resolver#versions_for. Run the supplied gem install reproduction and gem install --explain case. Done when both commands handle the resolved bb-1.1.0.rc1, aa-1.0.0, and cc-1.0.0 without the sorting error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the problem as clearly as you can

When gem cc depends on aa and bb >= 1.0, and aa depends on bb >= 1.1.0.rc1, running gem install cc without --pre resolves {cc 1.0.0, aa 1.0.0, bb 1.1.0.rc1} via Gem::Resolver, then crashes during install-order sorting with Gem::DependencyError: Unresolved dependency found during sorting - bb (requested by cc-1.0.0). gem install cc --explain crashes with the same error, whereas bundle install on Bundler 4.1.0 installs all three gems cleanly.

Gem::Resolver#versions_for admits prerelease versions per constraint via range_admits_prerelease? even when @prerelease is false, so PubGrub resolves bb-1.1.0.rc1 for the combined requirement. Afterwards, Gem::RequestSet#tsort_each_child (lib/rubygems/request_set.rb:537) checks dep.match?(r.spec.name, r.spec.version, r.spec.is_a?(Gem::Resolver::InstalledSpecification) || @prerelease) with @prerelease == false, which rejects bb-1.1.0.rc1 for cc's non-prerelease bb >= 1.0 dependency and raises Gem::DependencyError.

Did you try upgrading RubyGems?

Yes. Reproduced on RubyGems 4.1.0 (9af9267146) and ruby/rubygems master (5879ffe34b, 4.2.0.dev) on Ruby 4.0.9.

Post steps to reproduce the problem
mkdir /tmp/repro-gem41-sort && cd /tmp/repro-gem41-sort
mkdir -p repo/gems repo/quick/Marshal.4.8

ruby - << 'RUBY'
require "rubygems/package"
require "zlib"

specs = [
  Gem::Specification.new do |s|
    s.name = "cc"; s.version = "1.0.0"; s.summary = "cc"; s.authors = ["test"]
    s.add_dependency "aa"
    s.add_dependency "bb", ">= 1.0"
  end,
  Gem::Specification.new do |s|
    s.name = "aa"; s.version = "1.0.0"; s.summary = "aa"; s.authors = ["test"]
    s.add_dependency "bb", ">= 1.1.0.rc1"
  end,
  Gem::Specification.new do |s|
    s.name = "bb"; s.version = "1.0.0"; s.summary = "bb 1.0"; s.authors = ["test"]
  end,
  Gem::Specification.new do |s|
    s.name = "bb"; s.version = "1.1.0.rc1"; s.summary = "bb rc1"; s.authors = ["test"]
  end,
]

specs.each do |s|
  gem_file = Gem::Package.build(s, true)
  File.rename(gem_file, "repo/gems/" + gem_file)
  File.binwrite("repo/quick/Marshal.4.8/" + s.original_name + ".gemspec.rz",
    Zlib::Deflate.deflate(Marshal.dump(s)))
end

rel, pre = specs.partition { |s| !s.version.prerelease? }
File.binwrite("repo/specs.4.8.gz",
  Zlib.gzip(Marshal.dump(rel.map { |s| [s.name, s.version, "ruby"] })))
File.binwrite("repo/prerelease_specs.4.8.gz",
  Zlib.gzip(Marshal.dump(pre.map { |s| [s.name, s.version, "ruby"] })))
RUBY

gem install cc -i "$PWD/gemhome" --clear-sources --source "file://$PWD/repo" --no-document --backtrace
Which command did you run?

gem install cc -i "$PWD/gemhome" --clear-sources --source "file://$PWD/repo" --no-document --backtrace

What were you expecting to happen?

gem install cc installs bb-1.1.0.rc1, aa-1.0.0, and cc-1.0.0 in topological order without raising an internal sorting error, matching bundle install on Bundler 4.1.0:

Successfully installed bb-1.1.0.rc1
Successfully installed aa-1.0.0
Successfully installed cc-1.0.0
3 gems installed
What actually happened?
ERROR:  While executing gem ... (Gem::DependencyError)
    Unresolved dependency found during sorting - bb (requested by cc-1.0.0) (Gem::DependencyError)
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:543:in 'block in Gem::RequestSet#tsort_each_child'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:533:in 'Array#each'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:533:in 'Gem::RequestSet#tsort_each_child'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:418:in 'Method#call'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:418:in 'Gem::TSort.each_strongly_connected_component_from'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:352:in 'block in Gem::TSort.each_strongly_connected_component'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:529:in 'Array#each'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:529:in 'Gem::RequestSet#tsort_each_node'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:350:in 'Method#call'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:350:in 'Gem::TSort.each_strongly_connected_component'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:284:in 'Enumerator#each'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:284:in 'Enumerable#to_a'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:284:in 'Gem::TSort.strongly_connected_components'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/vendor/tsort/lib/tsort.rb:260:in 'Gem::TSort#strongly_connected_components'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:513:in 'Gem::RequestSet#sorted_requests'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:274:in 'Gem::RequestSet#install_into'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/request_set.rb:155:in 'Gem::RequestSet#install'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/commands/install_command.rb:212:in 'Gem::Commands::InstallCommand#install_gem'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/commands/install_command.rb:230:in 'block in Gem::Commands::InstallCommand#install_gems'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/commands/install_command.rb:223:in 'Array#each'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/commands/install_command.rb:223:in 'Gem::Commands::InstallCommand#install_gems'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/commands/install_command.rb:163:in 'Gem::Commands::InstallCommand#execute'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/command.rb:326:in 'Gem::Command#invoke_with_build_args'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/command_manager.rb:248:in 'Gem::CommandManager#invoke_command'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/command_manager.rb:189:in 'Gem::CommandManager#process_args'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/command_manager.rb:151:in 'Gem::CommandManager#run'
	/opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0/rubygems/gem_runner.rb:56:in 'Gem::GemRunner#run'
	/opt/ruby-4.0.9/bin/gem:12:in '<main>'
Run gem env and paste the output below
RubyGems Environment:
  - RUBYGEMS VERSION: 4.1.0
  - RUBY VERSION: 4.0.9 (2026-10-23 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /tmp/repro-gem41-sort/gemhome
  - USER INSTALLATION DIRECTORY: /home/user/.local/share/gem/ruby/4.0.0
  - CREDENTIALS FILE: /home/user/.local/share/gem/credentials
  - RUBYGEMS PREFIX: /opt/ruby-4.0.9/lib/ruby/site_ruby/4.0.0
  - RUBY EXECUTABLE: /opt/ruby-4.0.9/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /tmp/repro-gem41-sort/gemhome/bin
  - SPEC CACHE DIRECTORY: /home/user/.cache/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /opt/ruby-4.0.9/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
  - GEM PATHS:
     - /tmp/repro-gem41-sort/gemhome
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /opt/ruby-4.0.9/bin
     - /usr/bin
     - /bin

Credit: https://ucsbplse.github.io/

Lingua principale
Ruby
Stelle
4k
Fork
2k
Merge medio
1g 21h
PR unite (30g)
73

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rubygems

Tutte le issue di ruby/rubygems

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.