oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.36k stars 2.78k forks source link

elaborate on error "Expected Sink" #15234

Open paperdave opened 3 days ago

paperdave commented 3 days ago

Consider this code snippet.

let leakedCtrl;
using server = Bun.serve({
  async fetch(req) {
    return new Response(new ReadableStream({
      type: "direct",
      async pull(ctrl) {
        ctrl.write('a');
        await sleep(10);
        ctrl.write('b');
        ctrl.flush();
        leakedCtrl = ctrl;
      },
    } as any));
  },
});
let response = await fetch(server.url);
expect(await response.text()).toBe('ab');
leakedCtrl.write('more');

This used to throw Expected Sink, but now throws a more accurate error message:

17 |     } as any));
18 |   },
19 | });
20 | let response = await fetch(server.url);
21 | expect(await response.text()).toBe('ab');
22 | leakedCtrl.write('more');
                ^
error: This HTTPResponseSink has already been closed. A "direct" ReadableStream terminates its underlying socket once `async pull()` returns.

Closes #10632. the author should add await, an example of this is within ssr.tsx, it uses the controller out of the scope but also contains a promise that pull returns.

image

This PR also fixes the bug causing this, and writes being truncated, in the bake framework for react

robobun commented 3 days ago

:x: @paperdave, your commit ac110e910930f807da1325b5e7e01a200929ae0d has 25 failures in #6445:

  • test/js/web/fetch/fetch.tls.test.ts - 1 failing on 🍎 14 aarch64
  • test/js/web/fetch/fetch.stream.test.ts - 1 failing on 🍎 14 x64
  • test/js/bun/util/sleep.test.ts - 1 failing on 🐧 10 x64
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 aarch64
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 x64
  • test/js/bun/http/serve.test.ts - segmentation fault on 🐧 3.20 x64-baseline
  • test/js/bun/http/serve.test.ts - 1 failing on 🍎 14 x64
  • test/js/web/timers/setTimeout.test.js - 1 failing on 🐧 22.04 x64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🐧 20.04 x64
  • test/js/bun/shell/leak.test.ts - timeout on 🐧 10 aarch64
  • test/js/bun/shell/leak.test.ts - timeout on 🐧 10 x64-baseline
  • test/js/bun/shell/leak.test.ts - timeout on 🐧 10 x64
  • test/cli/run/filter-workspace.test.ts - 1 failing on 🐧 10 x64-baseline
  • test/cli/install/bun-link.test.ts - 4 failing on 🐧 3.20 aarch64
  • test/cli/install/bun-link.test.ts - 4 failing on 🐧 3.20 x64
  • test/cli/install/bun-link.test.ts - 4 failing on 🐧 3.20 x64-baseline
  • test/v8/v8.test.ts - timeout on 🐧 20.04 aarch64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 aarch64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64-baseline
  • test/regression/issue/ctrl-c.test.ts - 1 failing on 🐧 22.04 aarch64
  • test/regression/issue/ctrl-c.test.ts - 1 failing on 🐧 3.20 aarch64
  • test/js/bun/symbols.test.ts - 1 failing on 🐧 10 aarch64
  • test/js/bun/symbols.test.ts - 1 failing on 🐧 10 x64
  • test/js/bun/symbols.test.ts - 1 failing on 🐧 10 x64-baseline
  • test/js/bun/shell/bunshell.test.ts - timeout on 🐧 10 aarch64
  • test/js/bun/shell/bunshell.test.ts - timeout on 🐧 10 x64
  • test/js/bun/shell/bunshell.test.ts - timeout on 🐧 10 x64-baseline
  • test/js/node/child_process/child_process.test.ts - timeout on 🐧 2023 aarch64
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 aarch64
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64
  • test/js/node/child_process/child_process.test.ts - timeout on 🐧 2023 x64
  • test/js/node/child_process/child_process.test.ts - timeout on 🐧 2023 x64-baseline
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/cli/install/bun-run.test.ts - timeout on 🐧 2023 aarch64
  • test/cli/run/run-crash-handler.test.ts - timeout on 🐧 2023 aarch64
  • test/cli/run/run-crash-handler.test.ts - timeout on 🐧 2023 x64
  • test/cli/run/run-crash-handler.test.ts - timeout on 🐧 2023 x64-baseline
  • test/cli/install/registry/bun-install-registry.test.ts - timeout on 🐧 20.04 aarch64
  • test/cli/install/registry/bun-install-registry.test.ts - timeout on 🐧 22.04 x64
  • test/cli/install/registry/bun-install-registry.test.ts - timeout on 🐧 3.20 x64
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts - 1 failing on 🐧 10 aarch64
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts - 1 failing on 🐧 10 x64-baseline
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts - 1 failing on 🐧 10 x64
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts - 1 failing on 🐧 2023 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 11 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 10 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 12 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 2023 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 11 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 10 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 12 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 10 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 11 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 12 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 20.04 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 20.04 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 2023 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 2023 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64-baseline
  • test/js/third_party/body-parser/express-bun-build-compile.test.ts - 1 failing on 🐧 2023 aarch64
  • test/js/third_party/body-parser/express-bun-build-compile.test.ts - 1 failing on 🐧 2023 x64
  • test/js/third_party/body-parser/express-bun-build-compile.test.ts - 1 failing on 🐧 2023 x64-baseline
  • test/bundler/bundler_compile.test.ts - 1 failing on 🐧 10 aarch64
  • test/bundler/cli.test.ts - 1 failing on 🐧 2023 aarch64
  • test/bundler/cli.test.ts - 1 failing on 🐧 2023 x64
  • test/bundler/cli.test.ts - 1 failing on 🐧 2023 x64-baseline
  • test/js/bun/spawn/spawn.test.ts - timeout on πŸͺŸ 2019 x64
  • test/cli/inspect/inspect.test.ts - 1 failing on πŸͺŸ 2019 x64