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

Bun prevents connection closure #58

Open
apeman76 opened this issue Oct 5, 2024 · 5 comments
Open

Bun prevents connection closure #58

apeman76 opened this issue Oct 5, 2024 · 5 comments
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.

Comments

@apeman76
Copy link

apeman76 commented Oct 5, 2024

Hello,

Thanks for this library. I have been using it since atleast 0.3.7, but have not been active for a while.
Im back now and am using the most recent version, I noticed that with bun --bun run dev my connection closure function never gets called, but if I run it with node (bun run dev) it does get called.

I have no idea how to fix this, do you have any idea?
Im pretty much using the cleanup example now and it has this issue aswell: https://github.com/razshare/sveltekit-sse?tab=readme-ov-file#cleanup

@razshare razshare added the seen I've seen and read this issue and I'll try find some time soon to work on it. label Oct 5, 2024
@razshare
Copy link
Owner

razshare commented Oct 6, 2024

Hello @apeman76 , I think you're experiencing an issue with Bun itself or SvelteKit, I'm not exactly sure which one it is.

It looks like the ReadableStream class doesn't trigger the cancel method whenever the stream is consumed.

This can be either because SvelteKit doesn't trigger it, or because Bun's got some implementation issues.

I'm more inclined to say it's because of Bun itself, because it does work fine using NodeJs.

Note

well, now it does, after patch 0.13.9

The issue is this part here

cancel() {
lock.set(false)
},

it doesn't seem to trigger under Bun whenever the stream is consumed.

Here's a reproduction https://github.com/razshare/sveltekit-sse-issue-58

The code is not obfuscated with typescript stuff, so you can check the problem yourself by throwing in a console.log in there (see video below)

Peek 2024-10-06 11-32

I think you might have better luck opening an issue in https://github.com/oven-sh/bun

I'll try look into it more next week and possibly open an issue there myself explaining the situation.

If you get around to open an issue on their tracker before I do, please link back to this issue, so that I can see it referenced here and avoid creating duplicate issues, I'll do the same.

I'll leave this open for now.

@razshare
Copy link
Owner

razshare commented Oct 6, 2024

There's also this issue opened in kit sveltejs/kit#11751 (comment)

Though I don't think it's relevant anymore, because it works fine in NodeJs, it's just bun that doesn't work, and since bun promisses NodeJs compatibility it should be seen as a bun issue (I think).

@apeman76
Copy link
Author

apeman76 commented Oct 7, 2024

Im not sure what version of bun i'm on. It might be a few weeks old, then oven-sh/bun#6758 (comment) might have fixed it. Will report back when I have the chance to be on PC

/edit
Was already using bun 1.1.29, so that didnt fix it.
Opened oven-sh/bun#14390

@SaintPepsi
Copy link

I Assume the immediate workaround is just to not use bun?

I.e.

bun --bun run dev -> bun run dev it does get called.

@razshare
Copy link
Owner

Hello @SaintPepsi , yes, that is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.
Projects
None yet
Development

No branches or pull requests

3 participants