Spring

 Spring SSE Emitter Blocking on Browser Multiple Tabs

Aquilino Viveiros's profile image
Aquilino Viveiros posted Sep 19, 2019 12:43 AM

I have put together a Spring Boot 1.5.x MVC application with support for SSEs (SSE Emitter). When I have 1 or 2 browser tabs, everything works as expected. But if i open > 6 tabs .... the first 5 connect fine, the the following tabs start struggling to connect to the server.

 

Sample application is available here => https://github.com/aveiros/spring-sse

Browse to => http://localhost:9090/push/index.html

Click on "Duplicate" to duplicate current tab.

 

Any ideas?

Daniel Mikusa's profile image
Daniel Mikusa

> the the following tabs start struggling to connect to the server.

 

What do you mean by "struggling"? Does it connect? Does it fail to connect? Does it hang and not establish a connection? Does the browser actually try to connect? Have you tried using multiple browsers and not just different tabs in the same browser?

 

Can you get a HAR file from your browser's DevTools -> Networking screen?

Aquilino Viveiros's profile image
Aquilino Viveiros

6 tabs connect to the Server, the following ones get blocked. During the day I found out it's not Spring related.

 

For anyone struggling on this....

 

https://html.spec.whatwg.org/multipage/server-sent-events.html => Clients that support HTTP's per-server connection limitation might run into trouble when opening multiple pages from a site if each page has an EventSource to the same domain. Authors can avoid this using the relatively complex mechanism of using unique domain names per connection, or by allowing the user to enable or disable the EventSource functionality on a per-page basis, or by sharing a single EventSource object using a shared worker.

 

A SharedWorker (https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker) can be used to connect to a SSE endpoint and thus, sharing this (single) connection across tabs and not hitting the problem above. The only problem with this is that the support is not great.