Hacker News new | past | comments | ask | show | jobs | submit login

I tried implementing SSE in a web project of mine recently, and was very surprised when my website totally stopped working when I had more than 6 tabs open.

It turns out, Firefox counts SSE connections against the 6 host max connections limit, and gives absolutely no useful feedback that it's blocking the subsequent requests due to this limit (I don't remember the precise error code and message anymore, but it left me very clueless for a while). It was only when I stared at the lack of corresponding server side logs that it clicked.

I don't know if this same problem happens with websockets or not.






wait let's check this

https://news.ycombinator.com/item?id=42511562

at https://developer.mozilla.org/en-US/docs/Web/API/Server-sent... it says

"Warning: When not used over HTTP/2, SSE suffers from a limitation to the maximum number of open connections, which can be especially painful when opening multiple tabs, as the limit is per browser and is set to a very low number (6). The issue has been marked as "Won't fix" in Chrome and Firefox. This limit is per browser + domain, which means that you can open 6 SSE connections across all of the tabs to www.example1.com and another 6 SSE connections to www.example2.com (per Stack Overflow). When using HTTP/2, the maximum number of simultaneous HTTP streams is negotiated between the server and the client (defaults to 100)."

so the fix is just use http/2 on server-side?


Or a SharedWorker that creates a single SSE connection for all your tabs.

SharedWorker is not very complicated but it's another component to add. It would be cool if this was built into SSE instead.


okay wtf this is amazing, seems usable with websockets too.

usage of Shared Web Workers https://dev.to/ayushgp/scaling-websocket-connections-using-s...

caniuse Shared Web Workers 45% https://caniuse.com/sharedworkers

caniuse BroadcastChannel 96% https://caniuse.com/broadcastchannel


Yeah, the issue with SharedWorkers is that Android Chromium doesn't support it yet. https://issues.chromium.org/issues/40290702

But rather than Broadcast Channel, you can also use the Web Locks API (https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_A...) rather than Broadcast Channel

This library (https://github.com/pubkey/broadcast-channel/blob/master/src/...) from the fantastic RxDB javascript DB library uses WebLocks with a fallback to Broadcast Channel. But, WebLocks are supported on 96% of browsers, so probably safe to just use it exclusively now.


Ultimately this is what I did. But if you need or want per-tab connection state it will get complicated in a hurry.

Even if they don't change the default 6 open connection. They could have at least made it per tab rather than per site. [1] [2] And I dont understand why this hasn't been done in the past 10 years.

What am I missing?

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=906896

[2] https://issues.chromium.org/issues/40329530


That's only if not used over HTTP/2 and it says so in the docs too[0]

[0]: https://developer.mozilla.org/en-US/docs/Web/API/EventSource


AFAIK browsers require https with http2. This is a locally running server/app which will probably never have https. Maybe there is an exception for localhost, I'm not sure.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: