Skip to content

Thread deadlock in multiline command editing #461

Closed

Description

@dlanphear9

Description

In the last few weeks, we seem to have encountered errors in reline whilst editing multiline commands in the rails console.

Going down!

Full stacktrace:
49: from bin/rails:5:in <main>' 48: from /usr/local/bundle/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:332:in require'
47: from /usr/local/bundle/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:299:in load_dependency' 46: from /usr/local/bundle/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:332:in block in require'
45: from /usr/local/bundle/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require' 44: from /usr/local/bundle/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require'
43: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/commands.rb:18:in <main>' 42: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/command.rb:48:in invoke'
41: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/command/base.rb:69:in perform' 40: from /usr/local/bundle/gems/thor-1.2.1/lib/thor.rb:392:in dispatch'
39: from /usr/local/bundle/gems/thor-1.2.1/lib/thor/invocation.rb:127:in invoke_command' 38: from /usr/local/bundle/gems/thor-1.2.1/lib/thor/command.rb:27:in run'
37: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/commands/console/console_command.rb:102:in perform' 36: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/commands/console/console_command.rb:19:in start'
35: from /usr/local/bundle/gems/railties-6.1.6/lib/rails/commands/console/console_command.rb:70:in start' 34: from /usr/local/lib/ruby/2.7.0/irb.rb:400:in start'
33: from /usr/local/lib/ruby/2.7.0/irb.rb:471:in run' 32: from /usr/local/lib/ruby/2.7.0/irb.rb:471:in catch'
31: from /usr/local/lib/ruby/2.7.0/irb.rb:472:in block in run' 30: from /usr/local/lib/ruby/2.7.0/irb.rb:537:in eval_input'
29: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in each_top_level_statement' 28: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in catch'
27: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in block in each_top_level_statement' 26: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in loop'
25: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:154:in block (2 levels) in each_top_level_statement' 24: from /usr/local/lib/ruby/2.7.0/irb/ruby-lex.rb:182:in lex'
23: from /usr/local/lib/ruby/2.7.0/irb.rb:518:in block in eval_input' 22: from /usr/local/lib/ruby/2.7.0/irb.rb:704:in signal_status'
21: from /usr/local/lib/ruby/2.7.0/irb.rb:519:in block (2 levels) in eval_input' 20: from /usr/local/lib/ruby/2.7.0/irb/input-method.rb:294:in gets'
19: from /usr/local/lib/ruby/2.7.0/forwardable.rb:235:in readmultiline' 18: from /usr/local/lib/ruby/2.7.0/forwardable.rb:235:in readmultiline'
17: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:254:in readmultiline' 16: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:324:in inner_readline'
15: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:324:in loop' 14: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:326:in block in inner_readline'
13: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:373:in read_io' 12: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:373:in loop'
11: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:403:in block in read_io' 10: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:328:in block (2 levels) in inner_readline'
9: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:328:in each' 8: from /usr/local/bundle/gems/reline-0.3.1/lib/reline.rb:330:in block (3 levels) in inner_readline'
7: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/line_editor.rb:473:in rerender' 6: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/line_editor.rb:1000:in just_move_cursor'
5: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/ansi.rb:280:in move_cursor_column' 4: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/ansi.rb:280:in write'
3: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/line_editor.rb:226:in block in set_signal_handlers' 2: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/line_editor.rb:375:in move_cursor_down'
1: from /usr/local/bundle/gems/reline-0.3.1/lib/reline/ansi.rb:293:in move_cursor_down' /usr/local/bundle/gems/reline-0.3.1/lib/reline/ansi.rb:293:in write': deadlock; recursive locking (ThreadError)

Terminal Emulator

What's your terminal emulator? zsh

Activity

  1. tompng commented on May 7, 2023

    @tompng
    Member

    This is because Reline is doing too many things in Signal.trap(:INT){}.

    @old_trap = Signal.trap('INT') {
    clear_dialog(0)
    if @scroll_partial_screen
    move_cursor_down(@screen_height - (@line_index - @scroll_partial_screen) - 1)
    else
    move_cursor_down(@highest_in_all - @line_index - 1)
    end
    Reline::IOGate.move_cursor_column(0)
    scroll_down(1)
    case @old_trap
    when 'DEFAULT', 'SYSTEM_DEFAULT'
    raise Interrupt
    when 'IGNORE'
    # Do nothing
    when 'EXIT'
    exit
    else
    @old_trap.call if @old_trap.respond_to?(:call)
    end
    }

    It should be simple, ex: only assign to variable like

    Reline::IOGate.set_winch_handler do
    @resized = true
    end

    Deadlock reproducing code

    Signal.trap('INT') { STDOUT << 'a'}
    loop { STDOUT << 'a' }
    # long press Ctrl+C, and it will get deadlock
  2. added
    bug
    on Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions