irb
irb copied to clipboard
IRB hangs when using lots of CPU and CTRL+c does not work
If I paste this into IRB then I cannot ever exit:
10.times.each do
Thread.new do
while true
puts "."
end
end
end
If i hit CTRL+C I can see the input be registered in stdin but it never exits. I have to quit the entire tab.
$ gem list | grep irb
irb (1.2.0, default: 1.0.0)
⛄ 2.6.5 🚀 ~/Documents/projects/ruby (trunk)
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
I'm unsure if this is a bug. Your code invokes ten threads, and then terminates. You cannot kill the invoked threads by CTRL+C.
Regardless of the threads, IRB prompts your input correctly. So you can kill them by Thread#kill.
irb(main):001:0* ths = (1..10).map do
irb(main):002:0* Thread.new do
irb(main):003:1* while true
irb(main):004:1* sleep 5
irb(main):005:1* puts "."
irb(main):006:0* end
irb(main):007:-* end
irb(main):008:-> end
irb(main):009:0> ths.each .
.
..
.
.
.
.
.
.
irb(main):009:0> ths.each {|th| th.kill }..
.
.
..
.
.
.
.
irb(main):009:0> ths.each {|th| th.kill }
=> [#<Thread:0x00005654990fb2e0@(irb):2 sleep>, #<Thread:0x00005654990fb1c8@(irb):2 sleep>, #<Thread:0x00005654990fb0b0@(irb):2 sleep>, #<Thread:0x00005654990faf98@(irb):2 sleep>, #<Thread:0x00005654990fae80@(irb):2 sleep>, #<Thread:0x00005654990fad68@(irb):2 sleep>, #<Thread:0x00005654990fac50@(irb):2 sleep>, #<Thread:0x00005654990fab38@(irb):2 sleep>, #<Thread:0x00005654990faa20@(irb):2 sleep>, #<Thread:0x00005654990fa908@(irb):2 sleep>]
Note that this is reproducible with the old IRB.
Note that this is reproducible with the old IRB.
Ahh, good point I had never tried until today so didn't realize. Thank you! It does seem weird that CTRL+C is not recognized though but further IRB input is accepted. I don't think this is a blocker of any kind, but would ideally like CTRL+C to be respected whenever possible.
This is not a bug. CTRL+C is used to abort input in IRB. IRB should not stop other threads by CTRL+C, otherwise IRB will be unusable in debugging rails app (binding.irb in controller) and wrongly terminates important background job threads.