Skip to content

Detect unsettled top-level await and exit like Node (exit 13 + warning) #33283

Open

Description

@robobun

Split out from #14951, which was closed for its CPU-spin half (fixed by #32014: condition-gated drive loops now ref the event loop and park instead of busy-spinning).

The other half remains: when a module's top-level await never settles and nothing else refs the event loop, Node prints a warning and exits 13:

$ node -e 'await new Promise(() => {})'
Warning: Detected unsettled top-level await at [eval]:1
await new Promise(() => {})
^
$ echo $?
13

Bun's wait_for_promise refs the loop for the duration of the wait, so it waits for any pending unref'd timer and otherwise parks indefinitely rather than exiting. Verified against Node 26.3/26.4.

Implementing this means detecting "the module promise is pending and nothing other than this driver refs the loop", emitting the warning at the awaiting source location, and exiting 13. Two tests in test/js/web/timers/timers-unref-idle-loop.test.ts carry TODOs pointing here and assert today's divergent behavior (exit 0, no warning); they should be flipped as part of the fix.

Related: #31501 (closed as a duplicate of #14951).

Activity

  1. github-actions commented on Jul 2, 2026

    @github-actions
    Contributor

    Found 1 possible duplicate issue:

    1. Bun stuck without warning or error when top-level await is not resolved #22677

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. robobun commented on Jul 2, 2026

    @robobun
    CollaboratorAuthor

    ✅ Reproduced: an unsettled top-level await in the entry module (e.g. await new Promise(() => {})) spins at ~100% CPU and never exits; Node warns and exits 13.
    Fix (warn + exit 13, scoped to the main entry) → #33286

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions