closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

SystemStackError when trying to rebuild a tree with depth of 500.

Open phallstrom opened this issue 8 years ago • 3 comments

If you've got a hierarchy with a depth of around 500 you can't rebuild! the tree without it resulting in a SystemStackError: stack level too deep.

Here's a test that illustrates the failure. I don't have a patch or workaround, but wanted to report it.

    it 'rebuilds deeply nested tree' do
      parent = nil
      500.times do |counter|
        parent = Metal.create(:value => "Nitro-#{counter}", parent: parent)
      end
      expect { Metal.rebuild! }.not_to raise_error
    end

phallstrom avatar Jan 16 '18 20:01 phallstrom

@phallstrom that's the Ruby limit to ensure you don't have an infinite loop.

A quick Google search to increase the Ruby stack depth reveals this post on Stack Overflow: https://stackoverflow.com/questions/242617/how-to-increase-stack-size-for-a-ruby-app-recursive-app-getting-stack-level-to

Look at RUBY_THREAD_VM_STACK_SIZE and some of the other more recent posts for Ruby 2.0+

joelvh avatar Jan 28 '18 22:01 joelvh

@joelvh Agreed. I should have included that. Wanted to report the issue as in case others come across it and/or want to rewrite the code so it doesn't recurse and avoid the issue entirely.

phallstrom avatar Jan 29 '18 18:01 phallstrom

maybe we can write this into README.md and close this issue

saiqulhaq avatar Apr 16 '18 11:04 saiqulhaq