Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elaborate on error "Expected Sink" #15234

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

elaborate on error "Expected Sink" #15234

wants to merge 9 commits into from

Conversation

paperdave
Copy link
Member

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
Copy link

robobun commented Nov 19, 2024

@paperdave, your commit d46f780 has some failures in #6889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Expected Sink code: "ERR_INVALID_THIS"
2 participants