Using the irb:rdbg console corrupts irb_history by duplicating entries
joe-sharp opened this issue · 1 comments
Your environment
ruby -v
: 3.2.2 (and 3.0.6p216)rdbg -v
: 1.9.1irb -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!
~/dev/bundle-all 🔮❯❯❯ wc -l ~/.config/irb/irb_history.corrupt
24059398 /Users/joesharp/.config/irb/irb_history.corrupt
Sorry for the trouble. I've identified the cause and will open a PR this week.