镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Blob.stream().pipeTo() never resolves #48916

Description

@alanshaw

Version

20.5.0

Platform

Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

async function main () {
  const blob = new Blob([
    new Uint8Array([
       58, 162, 101, 114, 111, 111, 116, 115, 129, 216,  42,
       88,  37,   0,   1,  85,  18,  32,  95, 102, 197,  19,
      218,  30, 103,  78, 133, 139,  57, 105,  28,  11,   0,
      246, 124, 167,  41, 140, 239, 220, 248, 168, 136,  35,
      196,  72, 236, 184, 232,  89, 103, 118, 101, 114, 115,
      105, 111, 110,   1
    ]),
    new Uint8Array([ 68 ]),
    new Uint8Array([
        1,  85,  18,  32,  95, 102, 197,  19,
      218,  30, 103,  78, 133, 139,  57, 105,
       28,  11,   0, 246, 124, 167,  41, 140,
      239, 220, 248, 168, 136,  35, 196,  72,
      236, 184, 232,  89
    ]),
    new Uint8Array([
       90, 189, 174, 145, 144, 134, 214,
      117,  47, 251, 231, 254,  29, 238,
        0,  29, 212, 201, 123, 107,  95,
      130,  24, 168, 207, 139, 134, 177,
      187,  88, 167,  36
    ])
  ])
  await blob.stream().pipeTo(new WritableStream({
    write (chunk) {
      console.log(chunk)
    }
  }))
}

main().then(() => console.log('done')).catch(console.error)

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

Every run.

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

Expected to see all the chunks printed to console and then "done".

What do you see instead?

Uint8Array(59) [
   58, 162, 101, 114, 111, 111, 116, 115, 129, 216,  42,
   88,  37,   0,   1,  85,  18,  32,  95, 102, 197,  19,
  218,  30, 103,  78, 133, 139,  57, 105,  28,  11,   0,
  246, 124, 167,  41, 140, 239, 220, 248, 168, 136,  35,
  196,  72, 236, 184, 232,  89, 103, 118, 101, 114, 115,
  105, 111, 110,   1
]
Uint8Array(1) [ 68 ]

i.e. missing 2 chunks and no "done"

Additional information

No response

Activity

  1. bellbind commented on Jul 25, 2023

    @bellbind
    Contributor

    This code is OK on node-v20.3.1-darwin-arm64.tar.gz, and failed on node-v20.4.0-darwin-arm64.tar.gz

    other case:

    // blob.mjs
    import {describe, it, before, after} from "node:test";
    import {strict as assert} from "node:assert";
    
    describe("blob", async () => {
      it("stream", async () => {
        const bufs = [];
        const blob = new Blob(["A", "B", "C"]);
        await blob.stream().pipeTo(new WritableStream({
          write(chunk) {
            bufs.push(new TextDecoder().decode(chunk));
          }
        }));
        assert.equal(bufs.join(""), "ABC");
        //assert.deepEqual(bufs, ["A", "B", "C"]); //node-20.3.1
        //assert.deepEqual(bufs, ["ABC"]); //chrome and firefox
      });
    });
    $ asdf global nodejs 20.3.1
    $ node blob.mjs
    ▶ blob
      ✔ stream (6.642917ms)
    ▶ blob (7.957ms)
    
    ℹ tests 1
    ℹ suites 1
    ℹ pass 1
    ℹ fail 0
    ℹ cancelled 0
    ℹ skipped 0
    ℹ todo 0
    ℹ duration_ms 0.057125
    $ asdf global nodejs 20.4.0
    $ node blob.mjs
    ▶ blob
      ✖ stream (6.048208ms)
        'Promise resolution is still pending but the event loop has already resolved'
    
    ▶ blob (6.810833ms)
    
    ℹ tests 1
    ℹ suites 1
    ℹ pass 0
    ℹ fail 0
    ℹ cancelled 1
    ℹ skipped 0
    ℹ todo 0
    ℹ duration_ms 1.912083
    
    ✖ failing tests:
    
    ✖ stream (6.048208ms)
      'Promise resolution is still pending but the event loop has already resolved'
    
    ✖ blob (6.810833ms)
      'Promise resolution is still pending but the event loop has already resolved'

    I encountered the problem when using Blob with helia:

    import {describe, it} from "node:test";
    import {strict as assert} from "node:assert";
    
    import {createHelia} from "helia";
    import {unixfs} from "@helia/unixfs";
    
    describe("helia", async () => {
      it("unixfs.addByteStream", async () => {
        const node = await createHelia();
        const nodefs = unixfs(node);
    
        const blob = new Blob(["Hello World!"], {type: "text/plain"});
        const cid = await nodefs.addByteStream(blob.stream()); //never finished from nodejs>=20.4.0
        console.log(cid);
    
        await node.stop();
      });
    });

    From the blame list of lib/internal/blob.js, the bug spawned by the change of 8cc1438 .

    This issue may be same as #48668

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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions