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

key typing as ASCII sequences, and then freezes Ruby #871

Closed
jpriollaud opened this issue Dec 20, 2022 · 9 comments
Closed

key typing as ASCII sequences, and then freezes Ruby #871

jpriollaud opened this issue Dec 20, 2022 · 9 comments

Comments

@jpriollaud
Copy link

jpriollaud commented Dec 20, 2022

Your environment

  • ruby -v: 3.1.2
  • rdbg -v: 1.7.0

Describe the bug
From stack overflow:
"Ruby debug gem does not accept arrow keys and shows the key typing as ASCII sequences, and then frozes"

+1

binding.break

This is the result of up arrow key presses:
^[[A^[[A^[[A^[[A^

@ko1
Copy link
Collaborator

ko1 commented Dec 22, 2022

Sorry, I couldn't repr. On the stack overflow, DatabaseCleaner is related, but I have no knowledge about it.
Does anyone have idea?

@st0012
Copy link
Member

st0012 commented Dec 25, 2022

From the symptoms, it may have the same cause as #877. This is because by default typing up arrow key uses reline's history feature, which would then call Timeout.timeout underneath and triggers the problem described in #877.

One way to verify it is to add RUBY_DEBUG_NO_RELINE=1 and see if the problem still persists.

@connorshea
Copy link

I'm seeing the same behavior with going back in history using the up arrow on macOS, and RUBY_DEBUG_NO_RELINE=1 does indeed fix it.

@connorshea
Copy link

I've managed to reproduce it pretty consistently, and get this error:

connorshea@Connors-MacBook-Pro wikidatum % bundle exec ruby test.rb
[54, 63] in ~/code/wikidatum/lib/wikidatum/statement.rb
    54|   # statement in the API and turns it into an actual instance of a Statement.
    55|   #
    56|   # @param statement_json [Hash]
    57|   # @return [Wikidatum::Statement]
    58|   def self.marshal_load(statement_json)
=>  59|     debugger
    60|     mainsnak = Wikidatum::Snak.marshal_load(statement_json['mainsnak'])
    61| 
    62|     qualifiers = statement_json['qualifiers'].to_a.flat_map do |_qualifier_prop_id, qualifier|
    63|       qualifier.map { |q| Wikidatum::Qualifier.marshal_load(q) }
=>#0	Wikidatum::Statement.marshal_load(statement_json={"id"=>"Q11$2c668af1-4daf-cbe4-3893-2a615...) at ~/code/wikidatum/lib/wikidatum/statement.rb:59
  #1	block {|statement={"id"=>"Q11$2c668af1-4daf-cbe4-3893-2a615...|} in marshal_load (2 levels) at ~/code/wikidatum/lib/wikidatum/item.rb:187
  # and 7 frames (use `bt' command for all frames)
(ruby) statement_json["DEBUGGER Exception: /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:1233",
 #<fatal:"No live threads left. Deadlock?\n3 threads, 3 sleeps current:0x000000011d1aa3e0 main thread:0x000000012ce04620\n* #<Thread:0x0000000102e7b0f0 sleep_forever>\n   rb_thread_t:0x000000012ce04620 native:0x00000001e614fa80 int:0\n   \n* #<Thread:0x000000010628ae40@DEBUGGER__::SESSION@server /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:177 sleep_forever>\n   rb_thread_t:0x000000011d1aa3e0 native:0x000000016d397000 int:0\n   \n* #<Thread:0x000000010654a6f8@Timeout stdlib thread /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/3.2.0/timeout.rb:101 sleep_forever>\n   rb_thread_t:0x000000011d48acd0 native:0x000000016d5a3000 int:0\n   \n">,
 ["<internal:thread_sync>:18:in `pop'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:874:in `wait_next_action_'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:856:in `wait_next_action'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:320:in `suspend'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:251:in `on_breakpoint'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:69:in `suspend'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:178:in `block in setup'",
  "/Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:2586:in `debugger'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/statement.rb:59:in `marshal_load'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `block (2 levels) in marshal_load'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `map'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `block in marshal_load'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `each'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `flat_map'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `marshal_load'",
  "/Users/connorshea/code/wikidatum/lib/wikidatum/client.rb:93:in `item'",
  "test.rb:11:in `<main>'"]]
<internal:thread_sync>:18:in `pop': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x000000011d1aa3e0 main thread:0x000000012ce04620
* #<Thread:0x0000000102e7b0f0 sleep_forever>
   rb_thread_t:0x000000012ce04620 native:0x00000001e614fa80 int:0
   
* #<Thread:0x000000010628ae40@DEBUGGER__::SESSION@server /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:177 sleep_forever>
   rb_thread_t:0x000000011d1aa3e0 native:0x000000016d397000 int:0
   
* #<Thread:0x000000010654a6f8@Timeout stdlib thread /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/3.2.0/timeout.rb:101 sleep_forever>
   rb_thread_t:0x000000011d48acd0 native:0x000000016d5a3000 int:0
   

	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:874:in `wait_next_action_'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:856:in `wait_next_action'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:320:in `suspend'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:251:in `on_breakpoint'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:69:in `suspend'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:178:in `block in setup'
	from /Users/connorshea/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:2586:in `debugger'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/statement.rb:59:in `marshal_load'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `block (2 levels) in marshal_load'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `map'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:187:in `block in marshal_load'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `each'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `flat_map'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/item.rb:186:in `marshal_load'
	from /Users/connorshea/code/wikidatum/lib/wikidatum/client.rb:93:in `item'
	from test.rb:11:in `<main>'

I couldn't get a minimal repro case, I think it probably depends on the usage of faraday in my gem to eat up some of the threads? Not sure.

Here are the best repro steps I can get, I tested it on Ruby 3.2.0 but it may happen on 3.1 as well:

  • git clone https://github.com/connorshea/wikidatum
  • cd wikidatum
  • git checkout debug-gem-error-repro
  • bundle install
  • bundle exec ruby test.rb
  • That'll make a basic request to the Beta Wikidata API, and then trigger the debugger as it tries to serialize the data from the API.
  • In the debugger, you might need to do something to get the debug session to have a history, in which case you can just run statement_json to grab a local variable.
  • Then hit the up arrow, and it should crash the process.

I hope that helps!

@mtoygar
Copy link

mtoygar commented Feb 27, 2023

I am also seeing the same error. AFAIS, after I press any arrow keys for the second time, the process fails with the below error.

(rdbg) exit["DEBUGGER Exception: /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:1233",
 #<fatal:"No live threads left. Deadlock?\n3 threads, 3 sleeps current:0x00000001057a7520 main thread:0x0000000135604a50\n* #<Thread:0x000000010259b138 sleep_forever>\n   rb_thread_t:0x0000000135604a50 native:0x00000001f33b6500 int:0\n   \n* #<Thread:0x0000000105584070@DEBUGGER__::SESSION@server /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:177 sleep_forever>\n   rb_thread_t:0x00000001057a7520 native:0x000000016dc47000 int:0\n   \n* #<Thread:0x0000000105852b80@Timeout stdlib thread /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/timeout.rb:101 sleep_forever>\n   rb_thread_t:0x0000000105a7a650 native:0x000000016de53000 int:0\n   \n">,
 ["<internal:thread_sync>:18:in `pop'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:874:in `wait_next_action_'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:856:in `wait_next_action'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:320:in `suspend'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:251:in `on_breakpoint'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:69:in `suspend'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:178:in `block in setup'",
  "/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:2586:in `debugger'",
  "scraper.rb:11:in `call'",
  "scraper.rb:15:in `<main>'"]]
<internal:thread_sync>:18:in `pop': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x00000001057a7520 main thread:0x0000000135604a50
* #<Thread:0x000000010259b138 sleep_forever>
   rb_thread_t:0x0000000135604a50 native:0x00000001f33b6500 int:0

* #<Thread:0x0000000105584070@DEBUGGER__::SESSION@server /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:177 sleep_forever>
   rb_thread_t:0x00000001057a7520 native:0x000000016dc47000 int:0

* #<Thread:0x0000000105852b80@Timeout stdlib thread /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/timeout.rb:101 sleep_forever>
   rb_thread_t:0x0000000105a7a650 native:0x000000016de53000 int:0


	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:874:in `wait_next_action_'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:856:in `wait_next_action'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:320:in `suspend'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/thread_client.rb:251:in `on_breakpoint'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:69:in `suspend'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:178:in `block in setup'
	from /Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/session.rb:2586:in `debugger'
	from scraper.rb:11:in `call'
	from scraper.rb:15:in `<main>'

Output of bundle env;

➜ git:(main) ✗ bundle env
## Environment

Bundler             2.4.6
  Platforms         ruby, arm64-darwin-22
Ruby                3.2.1p31 (2023-02-08 revision 31819e82c88c6f8ecfaeb162519bfa26a14b21fd) [arm64-darwin-22]
  Full Path         /Users/murattoygar/.rvm/rubies/ruby-3.2.1/bin/ruby
  Config Dir        /Users/murattoygar/.rvm/rubies/ruby-3.2.1/etc
RubyGems            3.4.6
  Gem Home          /Users/murattoygar/.rvm/gems/ruby-3.2.1
  Gem Path          /Users/murattoygar/.rvm/gems/ruby-3.2.1:/Users/murattoygar/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0
  User Home         /Users/murattoygar
  User Path         /Users/murattoygar/.gem/ruby/3.2.0
  Bin Dir           /Users/murattoygar/.rvm/gems/ruby-3.2.1/bin
Tools
  Git               2.37.1 (Apple Git-137.1)
  RVM               1.29.12 (latest)
  rbenv             not installed
  chruby            not installed
  rubygems-bundler  (1.4.5)

## Bundler Build Metadata

Built At          2023-02-27
Git SHA           unknown
Released Version  false

## Gemfile

### Gemfile

source "https://rubygems.org"

gem 'nokogiri'

### Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    nokogiri (1.14.2-arm64-darwin)
      racc (~> 1.4)
    racc (1.6.2)

PLATFORMS
  arm64-darwin-22

DEPENDENCIES
  nokogiri

BUNDLED WITH
   2.4.6

I am getting this error when I run the below code via ruby scraper.rb

require 'uri'
require 'net/http'
require 'debug'
require 'nokogiri'

class Scraper
  def self.call
    uri = URI('https://google.com')
    res = Net::HTTP.get(uri) # => String

    binding.break
  end
end

Scraper.call

FWIW, RUBY_DEBUG_NO_RELINE=1 is also fixing my problem. Hope this helps!

@ko1
Copy link
Collaborator

ko1 commented Mar 7, 2023

Or using remote REPL (rdbg -O debuggee.rb) ...

@jpriollaud
Copy link
Author

RUBY_DEBUG_NO_RELINE=1 doesn't help. I have to terminate Ruby via System Monitor every 5 minutes of debugging.

@top4ek
Copy link

top4ek commented Jun 21, 2023

RUBY_DEBUG_NO_RELINE doesn't help, test just fails on binding.break with ENOENT.

ruby/3.2.0/gems/debug-1.8.0/lib/debug/console.rb:167:in `gets': No such file or directory @ rb_sysopen - -f (Errno::ENOENT)

@jpriollaud
Copy link
Author

Appears fixed in recent versions.

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

No branches or pull requests

6 participants