Handle infinite JS recursion

90 views
Skip to first unread message

Vinayaka Kamath

unread,
Feb 11, 2021, 3:14:06 AM2/11/21
to v8-users
Hello All,

I am trying to run a simple function which will hit recursion limit.

function foo(a) { 
return foo(a);
}

This is simple crashing the v8. I tried using both
isolate->SetFatalErrorHandler(fatal_error_callback);
isolate->SetOOMErrorHandler(oom_error_callback);

But neither of them are invoked when the program crashes. Is there any reliable way to make the program recursion free? I am using v8 8.3 BTW

Thanks a lot!

Ben Noordhuis

unread,
Feb 11, 2021, 5:31:56 AM2/11/21
to v8-users
You can catch stack overflow exceptions with a regular v8::TryCatch.

Vinayaka Kamath

unread,
Feb 11, 2021, 6:15:24 AM2/11/21
to v8-users
Ben, the Call() is inside a TryCatch, but seems like the call is not returning and just crashing even before the function Call is returning.

Ben Noordhuis

unread,
Feb 11, 2021, 6:35:51 AM2/11/21
to v8-users
On Thu, Feb 11, 2021 at 12:15 PM 'Vinayaka Kamath' via v8-users
<v8-u...@googlegroups.com> wrote:
>
> Ben, the Call() is inside a TryCatch, but seems like the call is not returning and just crashing even before the function Call is returning.

V8 makes an educated guess on how much real stack space is available.
It's possible it gets it wrong but you can pass `--stack_size <kb>` to
tell it how much there really is.

(Caveat emptor: that flag only *informs* V8 of the stack size, it
doesn't adjust it.)

If that doesn't fix the issue for you, please post a complete example
+ steps to reproduce the crash.
Reply all
Reply to author
Forward
0 new messages