-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
ReadableStream cancel is not called when client disconnects #6758
Comments
Any news on this? :/ |
@giesf I'm not exactly sure how it's supposed to work, but I got something working going off of the request abort signal rather than relying on the response cancel callback: const server = Bun.serve({
async fetch(req) {
const stream = new ReadableStream({
async start(controller) {
const encoder = new TextEncoder()
let count = 0
const interval = setInterval(() => {
controller.enqueue(encoder.encode(`${count }\n`))
}, 1000)
let closed = false
function close() {
if (closed) return
console.log('aborted')
closed = true
clearInterval(interval)
req.signal.removeEventListener('abort', close)
controller.close()
}
req.signal.addEventListener('abort', close)
if (req.signal.aborted) return close()
}
})
return new Response(stream)
}
}) Now running Is that what you're looking for? |
Any updates? |
We're using SSE for the "realtime" aspect of our SPA. Once these ReadableStreams are used up, the app freezes (because server event listeners don't get unregistered). So this isn't just a blocker for going to prod, but it's making development super annoying. Can we please have an ETA for a bug fix? |
What version of Bun is running?
1.0.7
What platform is your computer?
Debian Bullseye x64
What steps can reproduce the bug?
Running Bun with Svelte, in a API GET function:
What is the expected behavior?
Everytime the page is closed or the connection is closed by the client we should see a log on the server "cancelled".
What do you see instead?
Nothing is logged and the loop keeps running even if the page is fully closed.
Additional information
It works just fine with Node
The text was updated successfully, but these errors were encountered: