Skip to content

Crash from runaway recursion in a subquery-bodied function #7263

Description

@philrz

The following crashes with a fatal error: stack overflow rather than returning the error value described in the docs.

$ super -version &&
  super -s -c "
fn rec(n): (values n | values rec(this+1))
values rec(1)"

Version: v0.3.0-357-g0c71fac6a

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x1ea707b804d8 stack=[0x1ea707b80000, 0x1ea727b80000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xbdf3d5e?, 0x0?})
	/usr/local/opt/go/libexec/src/runtime/panic.go:1243 +0x48 fp=0x700005a8be28 sp=0x700005a8bdf8 pc=0xa4ac528
runtime.newstack()
	/usr/local/opt/go/libexec/src/runtime/stack.go:1207 +0x5dd fp=0x700005a8bf58 sp=0x700005a8be28 pc=0xa48b3fd
runtime.morestack()
	/usr/local/opt/go/libexec/src/runtime/asm_amd64.s:650 +0x7b fp=0x700005a8bf60 sp=0x700005a8bf58 pc=0xa4b285b
...

On my Intel Macbook, this ran for ~43 seconds and consumed ~1.5 GB of RAM before the crash.

Details

Repro is with super commit 0c71fac.

The error value is returned if the function body is a plain expression rather than a subquery:

$ super -s -c "
fn rec(n): rec(n+1)
values rec(1)"
error("stack overflow in function \"rec\"")

When using Claude to craft the simplified repro, it also gave its take on the root cause, which I've captured in a Gist.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions