-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ReadbleStream reads to completion in server, does not stream #1886
Comments
definitely a bug It's supposed to send off the stream as soon as the async tick happens In the meantime, could you try:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
What if you do this let body = new ReadableStream({
type: 'direct',
async pull(c) {
while (arr.length) {
c.write(arr.splice(0, 1)[0]);
c.flush();
await new Promise((resolve) => setTimeout(resolve, 1000));
}
c.close();
}); |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Flush was fixed on #3073 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
It is fixed with import { serve, file } from "bun";
serve({
port: 8443,
async fetch(req, server) {
console.log("fetch", req);
var remain = 10;
let body = new ReadableStream({
type: "direct",
async pull(c) {
while (remain--) {
c.write(new Date().toTimeString() + "\n");
c.flush();
await new Promise((resolve) => setTimeout(resolve, 1000));
}
c.close();
},
}); // TextEncoderStream() is undefined
return new Response(body, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Private-Network": "true",
},
});
},
}); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Can you paste the snippet with |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
are you on the canary build of bun? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Can confirm that the issue still exists. No change in behaviour with
|
Adding the "\n" into the output seems to make it work, though, but only with This does not work: let i = 0
serve({
port: SERVER_PORT,
fetch(req) {
let body = new ReadableStream({
type: 'direct',
async pull(controller) {
while (i++ < 10) {
controller.write(i.toString()) // <------- this line
controller.flush()
await wait(1000)
}
controller.close()
},
})
return new Response(body, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Private-Network': 'true',
},
})
},
}) This works as expected: let i = 0
serve({
port: SERVER_PORT,
fetch(req) {
let body = new ReadableStream({
type: 'direct',
async pull(controller) {
while (i++ < 10) {
controller.write(i.toString() + '\n') // <------- this line
controller.flush()
await wait(1000)
}
controller.close()
},
})
return new Response(body, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Private-Network': 'true',
},
})
},
}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
* Update WebKit * Don't do async hooks things when async hooks are not enabled * Smarter scheduling of event loop tasks with the http server * less exciting approach * Bump WebKit * Another approach * Fix body-stream tests * Fixes #1886 * Fix UAF in fetch body streaming * Missing from commit * Fix leak * Fix the other leak * Fix test * Fix crash * missing duperef * Make this code clearer * Ignore empty chunks * Fixes #3969 * Delete flaky test * Update bun-linux-build.yml * Fix memory issue * fix result body, and .done status before the last callback, dont touch headers after sent once * refactor HTTPClientResult * less flasky corrupted test * oops * fix mutex invalid state * fix onProgressUpdate deinit/unlock * fix onProgressUpdate deinit/unlock * oops * remove verbose * fix posible null use * avoid http null * metadata can still be used onReject after toResponse * dont leak task.http * fix flask tests * less flask close tests --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: cirospaciari <ciro.spaciari@gmail.com>
What version of Bun is running?
0.5.1
What platform is your computer?
x86_64 GNU/Linux
What steps can reproduce the bug?
bun_server.js
At
console
on Chromium 111What is the expected behavior?
What do you see instead?
Additional information
Using
deno
we get the expected resultThe text was updated successfully, but these errors were encountered: