hashicorp / sentinel-sdk

This SDK allows developers to extend Sentinel to source external information for use in their policies.
Mozilla Public License 2.0
51 stars 13 forks source link

Stack overflow on recursive rule #6

Closed tailhook closed 6 years ago

tailhook commented 7 years ago

I would assume it should be an error, not stack overflow:

a = rule { a }
main = a
> sentinel apply test.sentinel
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x9d1f0c, 0xe)
        /usr/local/go/src/runtime/panic.go:605 +0x95
runtime.newstack(0x0)
        /usr/local/go/src/runtime/stack.go:1050 +0x6e1
runtime.morestack()
        /usr/local/go/src/runtime/asm_amd64.s:415 +0x86

goroutine 1 [running]:
runtime.mapaccess2_fast64(0x91c2e0, 0xc42014f500, 0x5, 0x0, 0x0)
        /usr/local/go/src/runtime/hashmap_fast.go:159 +0x1be fp=0xc44018c318 sp=0xc44018c310 pc=0x40b69e
github.com/hashicorp/sentinel/runtime/eval.(*evalState).evalRuleObj(0xc4201781e0, 0xc420014ad8, 0x1, 0xc420011e00, 0xc420011e00, 0x0)
        /go/src/github.com/hashicorp/sentinel/runtime/eval/eval.go:1624 +0x510 fp=0xc44018c420 sp=0xc44018c318 pc=0x82b3c0
[ .. snip .. ]
> sentinel version            
Sentinel Simulator v0.1.0
mitchellh commented 6 years ago

It appears we're not setting the maximum stack depth on the simulator (which defaults to "system" stack depth which in our case is Go). We should set this to some reasonable amount and I will do this now.

A more clever system and improvement in the future would be to detect this of course.