Consider the following JS code (that is not the actual host obviously):
ws1 = new WebSocket("wss://myhost.com/ws/123/subscribe");
ws2 = new WebSocket("wss://myhost.com/ws/456/subscribe");
This should normally create 2 websockets listening on that host on 2 different topics. And this is what happens when I run it on Chrome.
But on Firefox only the first websocket opens and the second returns an error saying:
Firefox can’t establish a connection to the server at wss://myhost.com/ws/456/subscribe. And no further explanation. When looking at dev tools I see the following timings:
As I am informed in here, “blocked” does not mean there is a network issue or something like that, but it means that Firefox itself is blocking due to some configuration named:
network.http.max-persistent-connections-per-server
The default is supposed to be 6, but for me it behaves like it is 1.
I tried to raise this configuration to much higher values, but with no effect.
There is also one more configuration called:
network.websocket.max-connections
with a default of 200. This may be true for multiple hosts, but for multiple sockets on the same host it still behaves like 1. To test this I used a connection from an irrelevant example server. So when I run this code:
ws1 = new WebSocket("wss://echo.websocket.org/");
ws2 = new WebSocket("wss://echo.websocket.org/");
I get the same behavior as before. But when I mix it up like this:
ws1 = new WebSocket("wss://myhost.com/ws/123/subscribe");
ws2 = new WebSocket("wss://echo.websocket.org/");
Both connections open.
So is this a bug of Firefox or is it a feature? Does anyone know how to circumvent it?
So far the only solution I’m thinking involves a major redesign where I multiplex all my topics in a single socket and have the client de-multiplex them. But I’m really trying to avoid this.