oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.6k stars 2.72k forks source link

idleTimeout not working in WebSocket #1397

Closed ElYaiko closed 8 months ago

ElYaiko commented 1 year ago

What version of Bun is running?

0.2.1

What platform is your computer?

Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022;

What steps can reproduce the bug?

When I add the property idleTimeout to 8 for example, the connection keeps connected after not sending a message in more than 8 seconds.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

The server to close the connection after not sending a message in the timeout.

What do you see instead?

The connection keeps connected.

Additional information

No response

betamos commented 1 year ago

Is a bump inappropriate here?

I tried to trace the call chain to see if anything was missing in piping the params to uws. Bun seems to set both sendPingsAutomatically (although this is not exposed in the Bun APIs) and idleTimeout which should work. For instance, setting idleTimeout: 7 causes a C++ error in uws, which is expected. Unfortunately, I don't know Zig and wasn't able to dig in further.

The reason this is important in my view is:

Let me know if I can help.

Jarred-Sumner commented 1 year ago

I suspect this is related to HTTP Keep-Alive

betamos commented 1 year ago

HTTP Connection: keep-alive is not present with Websockets. TCP keep-alives should not make a difference either, since the timescales we're talking about are so small (10s-120s) that they're not reliable for detecting dead peers ~quickly.

In either case, uWebSockets should handle the full socket lifecycle in Bun, no? Since it's the same library, but different behavior, I'm thinking that something got messed up with the Zig -> C++ wiring. I just couldn't find what, everything looks good.

sheryy commented 1 year ago

Can someone please let me know If there is any plan to fix this bug soon? I cannot used Elysia (Bun based Web Framework) because of this issue.

If there is no plan to fix this issue then I will have no choice but to pick NodeJS v2.0, Fastify and uwebsocket.js to implement a real time communication module for my company.

Lan-Hekary commented 1 year ago

I am using bun v1.0.4 now and still the issue persists. seems like the properties sendPings and idleTimeout does not affect the behavior at all.