oven-sh / bun

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

direct readable stream does not always flush data when the connection closes #15235

Closed paperdave closed 11 hours ago

paperdave commented 3 days ago

What version of Bun is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

test("direct readable stream flushes data at end", async () => {
  using server = Bun.serve({
    port: 0,
    async fetch(req) {
      return new Response(new ReadableStream({
        type: "direct",
        async pull(ctrl: any) {
          ctrl.write('a');
          await sleep(10);
          ctrl.write('b');
          // ctrl.flush();
        },
      } as any));
    },
  });
  let response = await fetch(server.url);
  expect(await response.text()).toBe('ab');
});

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response