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

Using the irb:rdbg console corrupts irb_history by duplicating entries #855

Closed
joe-sharp opened this issue Jan 17, 2024 · 1 comment · Fixed by #853
Closed

Using the irb:rdbg console corrupts irb_history by duplicating entries #855

joe-sharp opened this issue Jan 17, 2024 · 1 comment · Fixed by #853

Comments

@joe-sharp
Copy link

Your environment

  • ruby -v: 3.2.2 (and 3.0.6p216)
  • rdbg -v: 1.9.1
  • irb -v: 1.11.1

Describe the bug
Ruby history doesn't remember history when using irb:rdbg as reported in ruby/debug#1054 but additionally it seems to duplicate things going into the history. After a couple hundred or so commands the history file can have millions of lines. It appears that irb:rdbg is putting the entire session history into the file for each line typed.
To Reproduce
I entered irb:rdbg and ran some commands. The history file already has more entries than it should, while also exhibiting the behavior described in ruby/debug#1054 . Finally returning to vanilla IRB I can see my history is back (with repeated commands).

Shell Session:

$ rm ~/.config/irb/irb_history
$ rdbg -c pry
[4, 13] in ~/.asdf/installs/ruby/3.2.2/bin/pry
     4| #
     5| # The application 'pry' is installed as part of a gem, and
     6| # this file is here to facilitate running it.
     7| #
     8|
=>   9| require 'rubygems'
    10|
    11| Gem.use_gemdeps
    12|
    13| version = ">= 0.a"
=>#0	<main> at ~/.asdf/installs/ruby/3.2.2/bin/pry:9
irb:rdbg(main):002> "this will appear four times"
"this will appear four times"
irb:rdbg(main):003> "this will appear three times"
"this will appear three times"
irb:rdbg(main):004> "this will appear two times"
"this will appear two times"
irb:rdbg(main):005> hist
3: hist
2: "this will appear two times"
1: "this will appear three times"
0: "this will appear four times"
=> nil
irb:rdbg(main):006>
[1] pry(main)>

$ wc -l ~/.config/irb/irb_history
      10 /Users/joesharp/.config/irb/irb_history
$ bat ~/.config/irb/irb_history
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /Users/joesharp/.config/irb/irb_history
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ "this will appear four times"
   2   │ "this will appear four times"
   3   │ "this will appear three times"
   4   │ "this will appear four times"
   5   │ "this will appear three times"
   6   │ "this will appear two times"
   7   │ "this will appear four times"
   8   │ "this will appear three times"
   9   │ "this will appear two times"
  10   │ hist

Expected behavior
I expect that the history file would only see each command once. Instead it appears to save the new command along with the entire previous history.

Additional context
Just for fun I noticed this issue when my performance got so bad that I couldn't get an IRB prompt anymore, when I checked the line count it was over 24 million!!! I have had this gem installed for only a few days! :hurtrealbad:

~/dev/bundle-all 🔮❯❯❯ wc -l ~/.config/irb/irb_history.corrupt
 24059398 /Users/joesharp/.config/irb/irb_history.corrupt
@st0012
Copy link
Member

st0012 commented Jan 31, 2024

Sorry for the trouble. I've identified the cause and will open a PR this week.

st0012 referenced this issue Jan 31, 2024
The issue (https://github.com/ruby/debug/issues/1064) is caused by a
combination of factors:

1. When user starts an IRB session without a history file, the
   `@loaded_history_lines` ivar is not defined.
2. If the user then starts the `irb:rdbg` session, the history counter
   is not set, because the `@loaded_history_lines` is not defined.
3. Because `irb:rdbg` saves the history before passing Ruby expression
   to the debugger, it saves the history with duplicated lines. The number
   grows in exponential order.
4. When the user exits the `irb:rdbg` session, the history file could be
   bloated with duplicated lines.

This commit fixes the issue by resetting the history counter even when
`@loaded_history_lines` is not defined.
st0012 referenced this issue Jan 31, 2024
The issue (https://github.com/ruby/debug/issues/1064) is caused by a
combination of factors:

1. When user starts an IRB session without a history file, the
   `@loaded_history_lines` ivar is not defined.
2. If the user then starts the `irb:rdbg` session, the history counter
   is not set, because the `@loaded_history_lines` is not defined.
3. Because `irb:rdbg` saves the history before passing Ruby expression
   to the debugger, it saves the history with duplicated lines. The number
   grows in exponential order.
4. When the user exits the `irb:rdbg` session, the history file could be
   bloated with duplicated lines.

This commit fixes the issue by resetting the history counter even when
`@loaded_history_lines` is not defined.
@hsbt hsbt transferred this issue from ruby/debug Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants