Closed bendillinger closed 11 months ago
Hi @bendillinger, thanks for asking this question, I'll try to help.
Expecting that the traversal would perform the same in or outside of a fiber.
Well, unfortunately, ruby fibers have a different stack than the main thread, and that stack is limited in size.
From https://docs.ruby-lang.org/en/master/Fiber.html:
As opposed to other stackless light weight concurrency models, each fiber comes with a stack. This enables the fiber to be paused from deeply nested function calls within the fiber block. See the ruby(1) manpage to configure the size of the fiber stack(s).
From the ruby man page:
STACK SIZE ENVIRONMENT
Stack size environment variables are implementation-dependent and subject to change with different versions of Ruby. The VM stack is used for pure-Ruby code and managed by the virtual machine. Machine stack is used by the operating system and its usage is dependent on C extensions as well as C compiler options. Using lower values for these may allow applications to keep more Fibers or Threads running; but increases the chance of SystemStackError exceptions and segmentation faults (SIGSEGV). These environment variables are available since Ruby 2.0.0. All values are specified in bytes.
RUBY_THREAD_VM_STACK_SIZE
- VM stack size used at thread creation. default: 131072 (32-bit CPU) or 262144 (64-bit)
RUBY_THREAD_MACHINE_STACK_SIZE
- Machine stack size used at thread creation. default: 524288 or 1048575
RUBY_FIBER_VM_STACK_SIZE
- VM stack size used at fiber creation. default: 65536 or 131072
RUBY_FIBER_MACHINE_STACK_SIZE
- Machine stack size used at fiber creation. default: 262144 or 524288
You should be able to set RUBY_FIBER_VM_STACK_SIZE and RUBY_FIBER_MACHINE_STACK_SIZE and improve this behavior.
Hope this helps!
@flavorjones Awesome thanks! That's incredibly informative
Please describe the bug
I'm seeing a
stack level too deep (SystemStackError)
parsing with Nokogiri, but only inside of a Fiber at a certain depth levelHelp us reproduce what you're seeing
Expected behavior
Expecting that the traversal would perform the same in or outside of a fiber.
Environment