-
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
socket.write does not work with node:http
#9882
Comments
We expect to reimlpement how node:http works internally but won't get around to it for another couple months most likely |
That explains it, thanks. |
node:http
Just ran into this issue, glad I found this issue since felt like I was going crazy! Was trying to destory the connection early if unauth'ed, etc. However
Trying to port some old server code I wrote, but also just wanted more control/integration into my custom framework. But after going in circles isolated it to this:
idk if that code is useful but might help for a future test case. On Node:
On Bun, it just hangs forever unless I stop the server. Looks like my new plan is to to just use Bun for package manager, bundling, cli tools and testing.... but target Node and run within Node for now until this and #7716 fixed, then switch back. Kinda frustrated but at least Bun supports targeting Node, so don't have to redo anything it seems with my codebase so far. |
I just hit this trying to intercept the upgrade process and wasted a day before I discovered Bun mocks in its own implementation of The key revelation in that replacement module is this: Lines 1167 to 1169 in c552cb4
So if you were planning to Like me, you might instead need to hack something like this: const kBunInternals = Symbol.for('::bunternal::');
const [_, response] = socket[kBunInternals];
response.writeHead(...);
response.end(); BTW, a common use case for this is rerouting websocket connections so all the clients in a given room are on the same server. The Fly.io proxy, for example will replay requests to the correct server instance if you respond to the upgrade with a magic fly-replay header, and this is the only place to do it. So yes, it would be great if the Bun mock for the socket behavior included the rest of the implementation, and didn't instead just hang silently 🤣 |
What version of Bun is running?
1.1.0+5903a6141
What platform is your computer?
Darwin 23.3.0 arm64 arm
What steps can reproduce the bug?
Run this in Bun:
Run this in a browser:
What is the expected behavior?
The
"x"
byte to be transferred over the TCP connection, and the following lines written to stdout:What do you see instead?
Only
and no data is transferred over the TCP connection, according to Wireshark. Both Node.js and Deno behave as expected.
Additional information
No response
The text was updated successfully, but these errors were encountered: