Skip to content

runtime: allow recursion depth limit #4692

Closed
@huandu

Description

@huandu
Per discussion in #4494 and
https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/hfEHWJKnHls, it's hard
to observe infinite recursion call in go. It's quite painful to find out root cause in a
large code base at least for me.

My suggestion is to introduce an env variable called GOMAXRECURSIONS to set a hard limit
on depth of recursion call. Once the limit is hit, panic the running goroutine. User
should be able to change its value at runtime, just like GOMAXPROCS.

The default limit can be a very large number, e.g. max int64, or just reuse current
strategy (no limit) to avoid any potential performance regression.

This variable should be designed for DEBUG purpose. Users can choose to set it in debug
version and unset it in product version. Or just set it when product version sucks up
abnormal cpu and memory without any clue. So, even if setting this variable will cause a
program 50% slower, it's still acceptable to me.

FYI: I don't think there would any scenario requires unlimit recursion call depth. It
would be great if go complier or vet or runtime could DETECT such infinite recursion and
show error/panic goroutine. Such detection logic would be quite risky (too smart,
maybe), so I wouldn't suggest to implement it. But I guess this is what I truly want...
Just FYI...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions