Skip to content

Keep the session alive when evaluated code raises Interrupt - #1279

Open
costajohnt wants to merge 1 commit into
ruby:masterfrom
costajohnt:fix-raise-interrupt
Open

costajohnt wants to merge 1 commit into
ruby:masterfrom
costajohnt:fix-raise-interrupt

Conversation

@costajohnt

Copy link
Copy Markdown

When code evaluated in IRB raises Interrupt (for example raise Interrupt, or a library that restored the default INT handler), IRB exits instead of printing the exception and returning to the prompt:

$ printf 'raise Interrupt\nputs :still_alive\n' | irb
(irb):1:in '<top (required)>': Interrupt (Interrupt)
...

still_alive is never printed.

Cause: in Irb#eval_input, Interrupt is a subclass of SignalException, so rescue SystemExit, SignalException re-raises it before the later rescue Interrupt, Exception clause can see it. Before 6269138 (#617) there was a separate rescue Interrupt => exc ahead of the SignalException clause; that commit folded it into the last clause, which made the Interrupt there unreachable.

Fix: restore a dedicated rescue Interrupt clause before rescue SystemExit, SignalException, handled the same way as other exceptions. Ctrl-C is unaffected since it goes through the SIGINT trap.

Test: added test_raise_interrupt_does_not_exit_irb to test/irb/test_raise_exception.rb. It fails on master (the irb process is killed by SIGINT) and passes with this change. bundle exec rake test and bundle exec rubocop pass.

Found with rbcop, RuboCop reimplemented in Rust.

Interrupt is a SignalException, so the SystemExit/SignalException clause
re-raised it before the later Interrupt clause could handle it. Restore the
dedicated Interrupt rescue that 6269138 (ruby#617) folded away.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant