Why doesn't Chrome reuse websocket connections across tabs?

615 views
Skip to first unread message

iychche

unread,
Apr 26, 2022, 12:11:26 PM4/26/22
to Chromium-dev
I am going through the article on Chrome internals here and my understanding is:
  1. The Chrome kernel process has the networking stack which is common for all render processes
  2. Before establishing a new connection, Chrome first checks if an open connection already exists as identified by {scheme, host, port}. 

I have a Websocket application that I access using wss://eventing.com/events. Each tab establishes a connection to that backend. However, given my understanding above, shouldn't I only see one connection that is shared between all tabs? What am I missing?

Thanks.

Reilly Grant

unread,
Apr 26, 2022, 12:49:57 PM4/26/22
to chengappa....@gmail.com, Chromium-dev
While normal HTTP requests can be sent over a single TCP (or QUIC) connection once a connection is being used for a WebSocket it consumes the entire connection. Conceptually, it is a single HTTP request which never ends. So that connection can't be reused. If WebSockets were supported over QUIC then theoretically a single QUIC connection could multiplex multiple WebSocket connections but that hasn't been implemented. If you want to share a single WebSocket between multiple tabs then I recommend having one tab own the connection and use BroadcastChannel to communicate events to the other tabs. 
Reilly Grant | Software Engineer | rei...@chromium.org | Google Chrome


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/3c2a413a-5059-4b0c-98e2-8f97c32c99a7n%40chromium.org.

Adam Rice

unread,
May 2, 2022, 3:40:00 AM5/2/22
to rei...@chromium.org, chengappa....@gmail.com, Chromium-dev
If you use WebSocket over HTTP/2 it should be possible for multiple WebSocket connections to share a single HTTP/2 connection, however this will only happen if there is an existing HTTP/2 connection to the destination host to start with (and the destination host must support WS/H2, obviously).

Reply all
Reply to author
Forward
0 new messages