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

bunx --bun vite preview hangs on request #12807

Closed
vjpr opened this issue Oct 14, 2024 · 3 comments
Closed

bunx --bun vite preview hangs on request #12807

vjpr opened this issue Oct 14, 2024 · 3 comments

Comments

@vjpr
Copy link

vjpr commented Oct 14, 2024

Describe the bug

I've traced the issue to here:

async function next() {
try {
for (;;) {
const { done, value } = await reader.read();
if (done) break;
if (!res.write(value)) {
res.once('drain', next);
return;
}
}
res.end();
} catch (error) {
cancel(error instanceof Error ? error : new Error(String(error)));
}
}
}

In Bun, done never becomes true.

In Node, it does and everything works fine.

If I add the following logs:

for (;;) {
				let { done, value } = await reader.read();

				console.log({done})
				if (done) break;

				console.log(res.write(value))
				if (!res.write(value)) {
					res.once('drain', next);
					return;
				}

			}
			res.end();

Node

{ done: false }
true
{ done: true }

Bun

{ done: false }
true

Reproduction

Bun

bunx --bun vite preview

Node

vite preview

Logs

No response

System Info

System:
    OS: macOS 15.0.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 72.44 MB / 128.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.8.0 - ~/Library/pnpm/node
    npm: 10.8.2 - ~/Library/pnpm/npm
    pnpm: 9.12.1 - ~/Library/pnpm/pnpm
    bun: 1.1.30 - ~/.bun/bin/bun
    Watchman: 2024.08.19.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 18.0.1

Severity

blocking all usage of SvelteKit

Additional Information

No response

@vjpr
Copy link
Author

vjpr commented Oct 14, 2024

Related: oven-sh/bun#6638

@vjpr
Copy link
Author

vjpr commented Oct 14, 2024

https://nodejs.org/api/http.html#requestwritechunk-encoding-callback

The callback argument is optional and will be called when this chunk of data is flushed, but only if the chunk is non-empty.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. 'drain' will be emitted when the buffer is free again.

When write function is called with empty string or buffer, it does nothing and waits for more input.

So in Bun, looks like the data is not flushed entirely, then SvelteKit listens for drain, which never comes.

When using res.on, it fires the drain event. But res.once doesn't.

Maybe res.once isn't implemented.

https://nodejs.org/api/stream.html#event-drain


  1. There is a descrepancy between Bun and Node behavior.
  2. Steam event once not implemented (for at least 'drain')

@eltigerchino
Copy link
Member

Sorry, but I'll be closing this issue because there isn't anything we should do on Kit's side of things. I think it's a very well investigated issue but better belongs in the Bun issue tracker.

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

No branches or pull requests

2 participants