Skip to content

Deep recursion in JIT-compiled code kills the process instead of raising SystemStackError #128

Closed

Description

@Largo

Deep recursion in a JIT-compiled method overflows the CLR stack and the process dies (Stack overflow. from the runtime, exit code 0xC00000FD / 134), where CRuby raises SystemStackError, which a program can rescue.

def f(n) = n == 0 ? 0 : 1 + f(n - 1)
p((f(1_000_000) rescue $!.class))   # CRuby: SystemStackError
where survives dies
Linux, main thread (8 MB) 100,000 1,000,000
Windows, main thread 20,000 30,000
Windows, Thread.new 3,000 30,000

The crash trace is all DynamicClass.jit$f frames under JitRuntime.SubInt, so the JIT's method bodies do not check the stack the way the interpreter's paths do (e.g. RuntimeHelpers.TryEnsureSufficientExecutionStack, which the Ractor copier uses to raise SystemStackError instead).

Possible fix: a stack check in the prologue of each JIT-compiled method (or every Nth call level) that raises SystemStackError.

Found while running PR #119 on Windows (2026-11-07), on that branch's net10.0 Debug build.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions