Signals not handled when main thread executes join #2835

Open
southerngs opened this Issue Dec 17, 2013 · 2 comments

Projects

None yet

3 participants

@southerngs
Contributor

I noticed that when creating multiple threads that Rubinius was not terminating my script when i pressed ctrl-c. The following is a simple script that demonstrates the problem:

Signal.trap("SIGINT") do
  puts "Caught SIGINT"
  exit
end

def func 
  while true do
    sleep(0.1)
    puts "Thread running"
  end
end

t = Thread.new{ func() }
t.join

When running this script with MRI, typing ctlr-c causes the program to exit with the message Caught SIGINT. But when run with Rubinius the script ignores ctrl-c and the rbx process has to be killed to terminate the program. Note that the signal handler and the printing are not necessary, I only added them to check why the process seemed hung. The following also has the same problem:

t = Thread.new{ while true do sleep(0.1) end }
t.join

And the problem is related to join because the following correctly catches and terminates the script when ctrl-c is typed:

t = Thread.new{ while true do sleep(0.1) end }
while true do sleep(0.1) end

I tested when building from head on the master branch while running with Ubuntu 12.04.

@YorickPeterse
Member

I can confirm that this issue persists in the current master branch. This is probably caused by Thread#join blocking the main thread, preventing it from receiving/handling signals. An option might be to run trapped signals in their own thread but we'll have to investigate what option is best.

@phuongnd08

+1 Kinda annoying when want to quickly terminate a stuck process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment