Live data from Hacker News

Server-Sent Events (SSE) Are Underrated

igorstechnoclub.com

41–50 of 153 posts

Re: Server-Sent Events (SSE) Are Underrated

#41

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 m…

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?

Re: Server-Sent Events (SSE) Are Underrated

#42

Earlier quoted context omitted.

There is little reason to not use HTTP/2 these days unless you are not doing TLS. I can understand not doing HTTP/3 and QUIC, but HTTP/2?

Corporate proxy servers often downgrade connections to HTTP 1.1 because inertia and lazy vendors.

To do that they need to MITM and tamper with the inner protocol.

In my experience this is quite rare. Some MITM proxies analyze the traffic, restrict which ciphers can be used, block non-dns udp (and therefore HTTP/3), but they don't usually downgrade the protocol from HTTP/2 to HTTP/1.

Re: Server-Sent Events (SSE) Are Underrated

#43

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 m…

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

Re: Server-Sent Events (SSE) Are Underrated

#44
post #22

Earlier quoted context omitted.

Generally you're going to want to send ping events pretty regularly (I'd default to every 15-30 seconds depending on application) whether you're using SSE, WebSockets, or something else. Otherwise if the server crashes the client might not know the connection is no longer live.

Yeah with cloudflare you need to do it every 30 seconds as the timeout is is 60 seconds

Then why not do it every 59 seconds :)

Re: Server-Sent Events (SSE) Are Underrated

#45

Also, another day, another mostly AI-written article on HN's top page :)

It’s funny how HN has a mix of people who think AGI is just around the corner, people trying to build/sell stuff that uses LLMs, and others who can’t stand LLM-generated content. Makes me wonder how much overlap there is between these groups.

I don't have anything against LLMs, I use them daily myself, but publishing content that's largely AI-generated without a disclaimer just feels dishonest to me. Oh, and also when people don't spend at least some effort to make the style more natural, not those bullet point lists in the article that e.g. Claude loves so much.

Re: Server-Sent Events (SSE) Are Underrated

#46
post #22

I utilized SSE when building automatic restart functionality[0] into Doppler's CLI. Our api server would send down an event whenever an application's secrets changed. The CLI would then fetch the latest secrets to inject into the application process. (I opted not to directly send the changed secrets via SSE as that would necessitate rechecking the access token that was used to establish the connection, lest we send c…

Generally you're going to want to send ping events pretty regularly (I'd default to every 15-30 seconds depending on application) whether you're using SSE, WebSockets, or something else. Otherwise if the server crashes the client might not know the connection is no longer live.

What do you do for mobile phones: using data/radio for pings would kill the battery?

After locking the phone, how is the ping restarted when the phone is unlocked? Or backgrounding the browser/app?

Re: Server-Sent Events (SSE) Are Underrated

#47

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 m…

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" i…

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.

Re: Server-Sent Events (SSE) Are Underrated

#48
post #33

Does anyone have a good trick for figuring out when the client side connection is closed? I just kill the connection on the server every N minutes and force the client to reconnect, but it's not exactly graceful. Secondly, on iOS mobile, I've noticed that the EventSource seems to fall asleep at some point and not wake up when you switch back to the PWA. Does anyone know what's up with that?

Send a dummy event and see if you get an ACK in response. Depends on the library you're using.

There's no ack on a raw SSE stream, unfortunately -- unless you mean send an event and expect the client to issue an HTTP request to the server like a keepalive?

Re: Server-Sent Events (SSE) Are Underrated

#49

Also, another day, another mostly AI-written article on HN's top page :)

It’s funny how HN has a mix of people who think AGI is just around the corner, people trying to build/sell stuff that uses LLMs, and others who can’t stand LLM-generated content. Makes me wonder how much overlap there is between these groups.

Those are not incompatible positions at all. You can think great AI is around the corner and still dislike today's not-great AI writing.

Re: Server-Sent Events (SSE) Are Underrated

#50

It doesn’t mention the big drawback of SSE as spelled out in the MDN docs: “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).”

You can easily multiplex data over one connection/event stream. You can design your app so that it only uses one eventstream for all events it needs to receive.

This, it works well in a service worker for example.
Post reply on HN