Skip to content

Awaiting a Promise between creating a stream and consuming a stream causes Node to crash with code 13 #48668

Description

@penalosa

Version

v20.4.0

Platform

Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64 arm Darwin

Subsystem

No response

What steps will reproduce the bug?

Run:

import { Blob } from "node:buffer";

const stream = new Blob(["Hello world"]).stream();

await Promise.resolve();

await stream.pipeTo(new WritableStream());
console.log("Done");

with node. The process will exit with code 13

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

Always reproduces when the line await Promise.resolve(); is included (or awaiting any promise). If that line is commented out the program prints "Done"

What is the expected behavior? Why is that the expected behavior?

I expect the sample program to run to completion and print "Done", as it does in node v20.3.1

What do you see instead?

Node exiting with code 13:

> node sample.mjs

> echo $?
13

Additional information

No response

Activity

  1. bnoordhuis commented on Jul 6, 2023

    @bnoordhuis
    Member

    It's mentioned in the documentation on node's exit codes:

    • 13 Unfinished Top-Level Await: await was used outside of a function
      in the top-level code, but the passed Promise never resolved.
  2. bnoordhuis commented on Jul 6, 2023

    @bnoordhuis
    Member

    I expect the sample program to run to completion and print "Done", as it does in node v20.3.1

    Sorry, I should have mentioned the old behavior was probably a bug. The new behavior is the expected behavior.

  3. bnoordhuis commented on Jul 6, 2023

    @bnoordhuis
    Member

    On second thought, I think this is indeed a bug, or at least an unintentional change in behavior introduced in f9c0d5a, cc @debadree25.

  4. added
    streamIssues and PRs related to Node.js streams.
    promisesIssues and PRs related to ECMAScript promises.
    and removed
    invalidIssues and PRs that are invalid.
    on Jul 6, 2023
  5. debadree25 commented on Jul 6, 2023

    @debadree25
    Contributor

    hello!

    hmm this does look like a bug so in my PR fixing hanging promises thing i am enqueing data during the microtask phase maybe thats causing some weird mixup in the event loop, I am investigating this! in the meanwhile do you think i should make a revert? in case this is breaking things?

  6. bricss commented on Jul 6, 2023

    @bricss
    Contributor

    I have an issue with blobs as well that started with Node v20.4.0, but it's related to blob to stream conversion and http2 client transfer, which is leading to readable stream to never close, hanging connection forever ♾️
    I will file a separate issue with reproduction example a bit later ⌚
    But atm it's reproducible by simply running tests for this npm package 📦 https://www.npmjs.com/package/rekwest

  7. bricss commented on Jul 6, 2023

    @bricss
    Contributor

    Here we go -> #48685

  8. asamuzaK commented on Jul 22, 2023

    @asamuzaK

    Similar bug with fetch.

    const file = new Blob(['<svg></svg>'], {
      type: 'image/svg+xml'
    });
    const url = URL.createObjectURL(file);
    const res = await fetch(url);
    const blob = await res.blob(); // does not resolve
    console.log(blob.size); // nothing logged
    

    It was working fine until v20.3.1.

    There is also #48157 for blob related fixes.

  9. bricss commented on Jul 22, 2023

    @bricss
    Contributor

    ISTM, that #48232 fixed hanging promises, but causing hanging streams right now 🤔
    And it might be missing pending.resolve() inside of queueMicrotask() 🔬

  10. debadree25 commented on Jul 22, 2023

    @debadree25
    Contributor

    And it might be missing pending.resolve() inside of queueMicrotask() 🔬

    But it does call promise resolve and reject inside the readNext fn

    Nonetheless sorry for the delay I shall get to investigating it by tomorrow!

  11. 9 remaining items

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

    promisesIssues and PRs related to ECMAScript promises.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions