`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

Đang mở
#10,085 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ruby
Lĩnh vực
backend, devtools

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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/

Ngôn ngữ chính
Ruby
Star
4k
Fork
2k
Merge trung bình
1 ngày 21 giờ
Pull request đã merge (30 ngày)
73

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/rubygems

Tất cả issue của ruby/rubygems

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.