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

Stop irb:rdbg from saving duplicated history when there's no prior history file #853

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Jan 31, 2024

The issue (#855) 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.

Closes #855

@st0012 st0012 added the bug Something isn't working label Jan 31, 2024
@st0012 st0012 self-assigned this Jan 31, 2024
@st0012 st0012 changed the title Reset history counter even when @loaded_history_lines is not defined Stop irb:rdbg from saving duplicated history when there's no prior history file Jan 31, 2024
step
irb_info
puts Reline::HISTORY.to_a.to_s
q!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, the history would be:

+ 'irb session'
+ next
+ 'irb session'
+ next
+ 'irb:debug session'
+ 'irb session'
+ next
+ 'irb:debug session'
+ step
+ 'irb session'
+ next
+ 'irb:debug session'
+ step
+ irb_info
+ puts Reline::HISTORY.to_a.to_s
  'irb session'
  next
  'irb:debug session'
  step
  irb_info
  puts Reline::HISTORY.to_a.to_s
  q!

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.
@tompng tompng merged commit 4afc98c into master Feb 1, 2024
55 checks passed
@tompng tompng deleted the fix-debug-#1064 branch February 1, 2024 16:19
matzbot pushed a commit to ruby/ruby that referenced this pull request Feb 1, 2024
not defined
(ruby/irb#853)

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.

ruby/irb@4afc98c258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Using the irb:rdbg console corrupts irb_history by duplicating entries
2 participants