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

SystemStackError: stack level too deep #665

Closed
alexandru-calinoiu opened this issue Jul 15, 2018 · 14 comments
Closed

SystemStackError: stack level too deep #665

alexandru-calinoiu opened this issue Jul 15, 2018 · 14 comments

Comments

@alexandru-calinoiu
Copy link

alexandru-calinoiu commented Jul 15, 2018

I constantly receive this error on a project with a relatively modest number of tests.

Happening in version 1.27.0 with ruby 1.5.1

Here is the full stack trace:

SystemStackError: stack level too deep
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:185:in `block in each_child_node'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each_child_node'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `each'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `flat_map'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `subjects_in_scope'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:50:in `find_subjects'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:40:in `block in subjects_in_scope'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:185:in `block in each_child_node'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each_child_node'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `each'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `flat_map'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:39:in `subjects_in_scope'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:50:in `find_subjects'
  /bundle/gems/rubocop-rspec-1.27.0/lib/rubocop/rspec/example_group.rb:40:in `block in subjects_in_scope'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:185:in `block in each_child_node'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each'
  /bundle/gems/rubocop-0.58.1/lib/rubocop/ast/node.rb:183:in `each_child_node'

And here is the spec that is failing:

RSpec.describe Api::Members::Repositories::Member, type: :repository do
  describe '#create' do
    subject(:create) { repository.create(new_member.to_h.merge(status_id: Factory[:account_status].id)) }

    let(:new_member) do
      build(:new_member,
            password_hash: 'hash',
            member_qualifications: [build(:member_qualification, qualification_id: Factory[:qualification].id),
                                    build(:member_qualification, qualification_id: Factory[:qualification, name: 'Paramedic'].id)])
    end
  end
end

It only seems to happen in docker machine.

@bquorning
Copy link
Collaborator

@Darhazer Do you have time to take a look at this one?

@Darhazer
Copy link
Member

I can't reproduce with the code snipped posted. @alexandru-calinoiu can you include the output of rubocop -V (in case it's specific Parser version that causes the issue)? Anything else specific to that docker machine?

@alexandru-calinoiu
Copy link
Author

Here is the docker file I am using:

FROM ruby:2.5.1-alpine

ENV APP_HOME /web/app
WORKDIR $APP_HOME

RUN apk update \
  && apk upgrade \
  && apk add \
    curl \
    wget \
    bash \
    build-base \
    libxml2-dev \
    libxslt-dev \
    postgresql-client \
    postgresql-dev \
    nodejs

# Clean APK cache
RUN rm -rf /var/cache/apk/*

# Prepare docs
WORKDIR $APP_HOME/docs

ENV BUNDLE_GEMFILE=$APP_HOME/docs/Gemfile \
  BUNDLE_JOBS=2 \
  BUNDLE_PATH=/bundle

RUN gem install bundler

# Prepare app
WORKDIR $APP_HOME

ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
  BUNDLE_JOBS=2 \
  BUNDLE_PATH=/bundle

RUN gem install bundler && gem install rake

The output for rubocop -V

0.58.1 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-linux-musl)

@Darhazer
Copy link
Member

Reproduced on the docker setup.
Interesting thing is that it crashes only when executed via bundle, e.g. bundle exec rubocop --require rubocop-rspec.
Direct invocation of rubocop --require rubocop-rspec does not crash.
Even more interesting is that executing 'gem install bundler` stops the crash, although the same version was already installed

@bquorning
Copy link
Collaborator

Do bundle exec rubocop -V and rubocop -V give the identical values?

@romatr
Copy link

romatr commented Jul 27, 2018

It might be related to this alpine dependent issue docker-library/ruby#196

@alexandru-calinoiu
Copy link
Author

It looks like it, I get the same error sometimes when I try to run rspec or cucumber.

@pirj
Copy link
Member

pirj commented Jul 10, 2019

Can we do something about this error by changing the code in this repository or rubocop's?

@alexandru-calinoiu
Copy link
Author

With the latest docker version I have not received this error anymore.

@pirj
Copy link
Member

pirj commented Jul 24, 2019

Seems this is not a problem anymore, should we close this?

@dgollahon
Copy link
Contributor

Seems reasonable to me. It can always be re-opened if the issue recurs.

@atanu2679

This comment has been minimized.

@houdinisparks
Copy link

houdinisparks commented Feb 2, 2024

Facing this error as well with

Versions:

/ # ruby --version
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux-musl]
/ # bundle --version
Bundler version 2.4.6
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.17.3
PRETTY_NAME="Alpine Linux v3.17"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
/
/ # docker --version
Docker version 23.0.6, build ef23cbc
/ # 
$ bundle exec rubocop
bundler: failed to load command: rubocop (/builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/bin/rubocop)
/builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each': stack level too deep (SystemStackError)
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/rspec/example_group.rb:51:in `each'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/rspec/example_group.rb:51:in `flat_map'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/rspec/example_group.rb:51:in `find_all_in_scope'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/rspec/example_group.rb:62:in `find_all'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/rspec/example_group.rb:52:in `block in find_all_in_scope'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
	from /builds/xxx/packages/app/vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
	 ... 251 levels...
	from /usr/local/rbenv/versions/3.2.1/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /usr/local/rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.4.6/libexec/bundle:33:in `<top (required)>'
	from /usr/local/rbenv/versions/3.2.1/bin/bundle:25:in `load'
	from /usr/local/rbenv/versions/3.2.1/bin/bundle:25:in `<main>'
Inspecting 453 files
.............................................................................................................................................................................................................................................................................................................................................................................................................................
412 files inspected, no offenses detected

Setting these env vars to increase te stack thread size does not help either:

$ export PTHREAD_STACK_MIN=8388608
$ export RUBY_THREAD_MACHINE_STACK_SIZE=8388608
$ export RUBY_THREAD_VM_STACK_SIZE=8388608

$ ruby -ve 'p RubyVM::DEFAULT_PARAMS'
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux-musl]
{:thread_vm_stack_size=>8388608, :thread_machine_stack_size=>8388608, :fiber_vm_stack_size=>131072, :fiber_machine_stack_size=>524288}

$ ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 125107
max locked memory           (kbytes, -l) 64
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1048576
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) unlimited
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited

I've also tried:

  • upgrading to alpine 3.18

It works locally with similar versions, and the stack thread size is also way lower:

$ ruby -ve 'p RubyVM::DEFAULT_PARAMS'                                                                                                                                                                                                                                                                                                                 [15:11:39]
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin21]
{:thread_vm_stack_size=>1048576, :thread_machine_stack_size=>1048576, :fiber_vm_stack_size=>131072, :fiber_machine_stack_size=>524288}

Any ideas?

@pirj
Copy link
Member

pirj commented Feb 2, 2024

Can you please the rubocop debug output and the minimal spec code that would allow to reproduce the issue, @houdinisparks ?

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

No branches or pull requests

8 participants