Skip to content

Repl Crashes in infinite Async recursion #40502

Description

@ramonGonzEdu

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.

Activity

  1. targos commented on Oct 18, 2021

    @targos
    Member

    @nodejs/repl

  2. added
    replIssues and PRs related to the REPL subsystem.
    on Oct 18, 2021
  3. added
    linuxIssues and PRs related to the Linux platform.
    on Oct 18, 2021
  4. BridgeAR commented on Nov 29, 2021

    @BridgeAR
    Member

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

  5. yashLadha commented on Mar 1, 2022

    @yashLadha
    Contributor

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

  6. yashLadha commented on Mar 1, 2022

    @yashLadha
    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
    
  7. targos commented on Mar 1, 2022

    @targos
    Member

    V8 doesn't implement TCO.

  8. yashLadha commented on Mar 8, 2022

    @yashLadha
    Contributor

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

  9. yashLadha commented on Mar 12, 2022

    @yashLadha
    Contributor

    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)```
  10. avivkeller commented on Jun 20, 2026

    @avivkeller
    Member

    I can't reproduce in the latest version of Node.js

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

    confirmed-bugIssues and PRs for confirmed bugs.linuxIssues and PRs related to the Linux platform.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions