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

Infinite loop in --fix #289

Closed
mperham opened this issue May 5, 2021 · 5 comments · Fixed by rubocop/rubocop#9777 or #296
Closed

Infinite loop in --fix #289

mperham opened this issue May 5, 2021 · 5 comments · Fixed by rubocop/rubocop#9777 or #296
Labels
rubocop bug 🚨 An apparent bug in RuboCop

Comments

@mperham
Copy link
Contributor

mperham commented May 5, 2021

Only crashes with --fix.

# testy.rb
module Foo
  module Bar
    class Baz
      def helper
        @helper ||= begin
                      if @type == "c"
                       Concurrent.new(@key, @name)
                     elsif @type == "w"
                        Window.new(@key, @name)
                     elsif @type == "b"
                        Bucket.new(@key, @name)
                     elsif @type == "k"
                        LeakyBucket.new(@key, @name)
                     else
                        raise ArgumentError, "Unknown limiter key #{key}"
        end
                    end

      end
    end
  end
end
❯ standardrb --fix testy.rb
Traceback (most recent call last):
	31: from /Users/mikeperham/.gem/ruby/2.7.2/bin/standardrb:23:in `<main>'
	30: from /Users/mikeperham/.gem/ruby/2.7.2/bin/standardrb:23:in `load'
	29: from /Users/mikeperham/.gem/ruby/2.7.2/gems/standard-1.1.1/exe/standardrb:7:in `<top (required)>'
	28: from /Users/mikeperham/.gem/ruby/2.7.2/gems/standard-1.1.1/lib/standard/cli.rb:14:in `run'
	27: from /Users/mikeperham/.gem/ruby/2.7.2/gems/standard-1.1.1/lib/standard/runners/rubocop.rb:15:in `call'
	26: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
	25: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
	24: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
	23: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
	22: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:46:in `run'
	21: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:67:in `warm_cache'
	20: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:232:in `each'
	19: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:283:in `map'
	18: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:380:in `work_in_processes'
	17: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:440:in `create_workers'
	16: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:440:in `each_with_index'
	15: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:440:in `each'
	14: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:441:in `block in create_workers'
	13: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:450:in `worker'
	12: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:450:in `fork'
	11: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:459:in `block in worker'
	10: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:477:in `process_incoming_jobs'
	 9: from /Users/mikeperham/.gem/ruby/2.7.2/gems/parallel-1.20.1/lib/parallel.rb:509:in `call_with_index'
	 8: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:67:in `block in warm_cache'
	 7: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:129:in `file_offenses'
	 6: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
	 5: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
	 4: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:250:in `do_inspection_loop'
	 3: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
	 2: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:281:in `loop'
	 1: from /Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:282:in `block in iterate_until_no_changes'
/Users/mikeperham/.gem/ruby/2.7.2/gems/rubocop-1.14.0/lib/rubocop/runner.rb:299:in `check_for_infinite_loop': RuboCop::Runner::InfiniteCorrectionLoop: Infinite loop detected in /Users/mikeperham/src/ent/testy.rb and caused by Layout/BeginEndAlignment, Layout/ElseAlignment, Layout/EmptyLinesAroundMethodBody, Layout/EndAlignment, Layout/IndentationWidth, Style/RedundantBegin -> Layout/IndentationWidth, Style/RedundantBegin -> Layout/ElseAlignment, Layout/EndAlignment, Layout/IndentationWidth, Layout/TrailingWhitespace, Style/MultilineMemoization (Parallel::UndumpableException)
@searls
Copy link
Contributor

searls commented May 6, 2021

That's a real weird end, mike!

I think any infinite loop condition should be filed against since we're only configuring built-in rules. Is that true, @koic? https://github.com/rubocop/rubocop

@koic
Copy link
Contributor

koic commented May 6, 2021

@searls This issue has been reproduced as a bug in RuboCop. I will take it. Thank you for your mention!

@koic
Copy link
Contributor

koic commented May 6, 2021

I opened rubocop/rubocop#9777 to solve this issue.

@jmkoni jmkoni added the rubocop bug 🚨 An apparent bug in RuboCop label May 6, 2021
@jmkoni
Copy link
Contributor

jmkoni commented May 6, 2021

Thanks @koic!

@koic
Copy link
Contributor

koic commented May 6, 2021

You are welcome @jmkoni!

koic added a commit to koic/rubocop that referenced this issue May 7, 2021
This PR fixes an incorrect auto-correct for `Style/RedundantBegin`
when using multi-line `if` in `begin` block.

And fixes standardrb/standard#289 that is causing
the following infinite loop error due to `Style/RedundantBegin` with
`Style/MultilineMemoization`.

```ruby
% cat example.rb
@memo ||= begin
  if condition
    do_something
  end
end

% bundle exec rubocop -a --only Style/RedundantBegin,Style/MultilineMemoization
(snip)

Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Style/MultilineMemoization: Wrap
multiline memoization blocks in begin and end.
@memo ||= (if condition ...
^^^^^^^^^^^^^^^^^^^^^^^
example.rb:1:11: C: [Corrected] Style/RedundantBegin: Redundant begin
block detected.
@memo ||= begin
          ^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in
/Users/koic/src/github.com/koic/rubocop-issues/289/example.rb and caused
by Style/MultilineMemoization
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:285:in
`block in iterate_until_no_changes'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in
`loop'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
```
bbatsov pushed a commit to rubocop/rubocop that referenced this issue May 7, 2021
This PR fixes an incorrect auto-correct for `Style/RedundantBegin`
when using multi-line `if` in `begin` block.

And fixes standardrb/standard#289 that is causing
the following infinite loop error due to `Style/RedundantBegin` with
`Style/MultilineMemoization`.

```ruby
% cat example.rb
@memo ||= begin
  if condition
    do_something
  end
end

% bundle exec rubocop -a --only Style/RedundantBegin,Style/MultilineMemoization
(snip)

Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Style/MultilineMemoization: Wrap
multiline memoization blocks in begin and end.
@memo ||= (if condition ...
^^^^^^^^^^^^^^^^^^^^^^^
example.rb:1:11: C: [Corrected] Style/RedundantBegin: Redundant begin
block detected.
@memo ||= begin
          ^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in
/Users/koic/src/github.com/koic/rubocop-issues/289/example.rb and caused
by Style/MultilineMemoization
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:285:in
`block in iterate_until_no_changes'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in
`loop'
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rubocop bug 🚨 An apparent bug in RuboCop
Projects
None yet
4 participants