Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedHelpers.trap assumes the prior handler for the signal is callable #4764

Closed
haines opened this issue Jul 15, 2021 · 1 comment · Fixed by #4767
Closed

SharedHelpers.trap assumes the prior handler for the signal is callable #4764

haines opened this issue Jul 15, 2021 · 1 comment · Fixed by #4767

Comments

@haines
Copy link
Contributor

haines commented Jul 15, 2021

Describe the problem as clearly as you can

SharedHelpers.trap attempts to preserve any existing handler for a signal by invoking call on it.

def trap(signal, override = false, &block)
prior = Signal.trap(signal) do
block.call
prior.call unless override
end
end

However, prior can be a string, resulting in

NoMethodError: undefined method `call' for "DEFAULT":String

Post steps to reproduce the problem

Run this script:

# frozen_string_literal: true

require 'bundler/inline'

gemfile true do # force installation so that SharedHelpers.trap('INT') is called in Bundler::Worker#initialize
  source 'https://rubygems.org'
  gem 'rake'
end

Process.kill 'INT', Process.pid
# => bundler/shared_helpers.rb:158:in `block in trap': undefined method `call' for "DEFAULT":String (NoMethodError)

Which command did you run?

bundler/inline

What were you expecting to happen?

I get the standard Ruby Interrupt exception when I interrupt the script

What actually happened?

If Bundler installed any gems, I get NoMethodError. If Bundler did not install any gems (and therefore did not trap SIGINT) then I get the correct Interrupt.

If not included with the output of your command, run bundle env and paste the output below

Bundler       2.2.23
  Platforms   ruby, x86_64-darwin-20
Ruby          2.7.3p183 (2021-04-05 revision 6847ee089d7655b2a0eea4fee3133aeacd4cc7cc) [x86_64-darwin20]
  Full Path   /Users/andrew/.rubies/ruby-2.7.3/bin/ruby
  Config Dir  /Users/andrew/.rubies/ruby-2.7.3/etc
RubyGems      3.2.23
  Gem Home    /Users/andrew/.gem/ruby/2.7.3
  Gem Path    /Users/andrew/.gem/ruby/2.7.3:/Users/andrew/.rubies/ruby-2.7.3/lib/ruby/gems/2.7.0
  User Home   /Users/andrew
  User Path   /Users/andrew/.gem/ruby/2.7.0
  Bin Dir     /Users/andrew/.gem/ruby/2.7.3/bin
Tools         
  Git         2.32.0
  RVM         not installed
  rbenv       not installed
  chruby      0.3.9
@haines haines added the Bundler label Jul 15, 2021
@deivid-rodriguez
Copy link
Member

Thanks for the report. Can you send us a patch?

haines added a commit to haines/rubygems that referenced this issue Jul 15, 2021
SharedHelpers.trap failed when the previous handler for a signal is not callable
(for example, when it is the string "DEFAULT").

Instead, we now handle interrupts by aborting the process when worker threads are
running, and restore the previous handler after worker threads are finished.

Fixes rubygems#4764.
haines added a commit to haines/rubygems that referenced this issue Jul 15, 2021
The existing interrupt handling using `SharedHelpers.trap` fails when the previous
handler for a signal is not callable (for example, when it is the string "DEFAULT").

Instead, we now handle interrupts by aborting the process when worker threads are
running, and restore the previous handler after worker threads are finished.

Fixes rubygems#4764.
haines added a commit to haines/rubygems that referenced this issue Jul 15, 2021
The existing interrupt handling using `SharedHelpers.trap` fails when the previous
handler for a signal is not callable (for example, when it is the string "DEFAULT").

Instead, we now handle interrupts by aborting the process when worker threads are
running, and restore the previous handler after worker threads are finished.

Fixes rubygems#4764.
haines added a commit to haines/rubygems that referenced this issue Jul 15, 2021
The existing interrupt handling using `SharedHelpers.trap` fails when the previous
handler for a signal is not callable (for example, when it is the string "DEFAULT").

Instead, we now handle interrupts by aborting the process when worker threads are
running, and restore the previous handler after worker threads are finished.

Fixes rubygems#4764.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants