Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repl Crashes in infinite Async recursion #40502

Open
ramonGonzEdu opened this issue Oct 18, 2021 · 7 comments
Open

Repl Crashes in infinite Async recursion #40502

ramonGonzEdu opened this issue Oct 18, 2021 · 7 comments
Labels
confirmed-bug Issues with confirmed bugs. linux Issues and PRs related to the Linux platform. repl Issues and PRs related to the REPL subsystem.

Comments

@ramonGonzEdu
Copy link

Version

v16.1.0

Platform

Linux linx-PC 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

Repl

What steps will reproduce the bug?

  1. Open node repl
  2. Type (async (a)=>a(a))(async (a)=>a(a)) but don't press return
  3. Crash

How often does it reproduce? Is there a required condition?

100% of the time.

What is the expected behavior?

The repl should not crash.

What do you see instead?

RangeError: Maximum call stack size exceeded
    at <anonymous>:1:19
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30
    at <anonymous>:1:30

Additional information

Typing (a=>a(a))(a=>a(a)) doesn't crash and only prints the error after you press enter.

@targos
Copy link
Member

targos commented Oct 18, 2021

@nodejs/repl

@targos targos added the repl Issues and PRs related to the REPL subsystem. label Oct 18, 2021
@iam-frankqiu iam-frankqiu added the linux Issues and PRs related to the Linux platform. label Oct 18, 2021
@BridgeAR BridgeAR added the confirmed-bug Issues with confirmed bugs. label Nov 29, 2021
@BridgeAR
Copy link
Member

Pressing enter crashes the REPL with newer versions. This is likely an issue due to top level away support?

@yashLadha
Copy link
Contributor

When building on master it is crashing without pressing enter as well @BridgeAR .

@yashLadha
Copy link
Contributor

On further deep-dive it seems TCO (Tail call optimisation) is not kicking in. To verify this hypothesis i have written a simple script

'use strict';

const fn = (a) => {
  a(a);
}

fn(fn);

On executing the above script it is always erroring out with StackOverflow

❯ ./node crash.js          
/Users/yashLadha/opensource/node/crash.js:4
  a(a);
  ^

RangeError: Maximum call stack size exceeded
  ....

Node.js v18.0.0-pre

@targos
Copy link
Member

targos commented Mar 1, 2022

V8 doesn't implement TCO.

@yashLadha
Copy link
Contributor

Then isn't the expected behaviour in the issue template seems wrong?

@yashLadha
Copy link
Contributor

yashLadha commented Mar 12, 2022

One more thing if you change the snippet just slightly.

(async (a) => process.nextTick(() => a(a)))(async (a) => process.nextTick(() => a(a)))

It won't crash the repl as stack won't exceed but might end up in the following error:

> RangeError: Map maximum size exceeded
    at Map.set (<anonymous>)
    at AsyncHook.init (node:domain:76:15)
    at emitInitNative (node:internal/async_hooks:201:43)
    at emitInitScript (node:internal/async_hooks:506:3)
    at promiseInitHook (node:internal/async_hooks:321:3)
    at promiseInitHookWithDestroyTracking (node:internal/async_hooks:325:3)
    at REPL1:1:45
    at REPL1:1:81
    at processTicksAndRejections (node:internal/process/task_queues:77:11)```

@RedYetiDev RedYetiDev mentioned this issue Jun 24, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. linux Issues and PRs related to the Linux platform. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants
@targos @BridgeAR @yashLadha @iam-frankqiu @ramonGonzEdu and others