23

I recently found out that Chrome seems to have a connection limit of 6 ( Chrome hangs after certain amount of data transfered - waiting for available socket ) unfortunately I found this out the hard way by getting a "waiting for available sockets" message after loading up too many tabs (7).

I know it is Chrome since another Chrome user (a.k.a another browser session) loads the web page perfectly fine on the same computer at the same time (I have multiple Chrome users open on my computer). So it is not the server in any way.

I believe this is because, in socket.io (which I am using for notifications), I am xhr-polling which is causing Chrome to have to wait until it can grab a socket from one of those connections before it can process the page.

What is the solution to this?

I have thought of a couple of solutions:

  • make the xhr-polling window smaller, this increases connections in the browser and node.js but will mean the page won't stall.
  • Use websockets. I am unsure if websockets are immune to this problem either.
  • Make connections inactive on tabs not focused. Though it seems other sites don't have to do that...
  • Use some kind of connection sharing. Considering that Chrome isolates websockets and xhr requests to the tab I do find it difficult to understand how that works.

As an added point: the reason I have not gone with websockets from the start is because I use cloudflare. But if this is the way to solve it then: so be it.

Community
  • 1
  • 1
Sammaye
  • 43,242
  • 7
  • 104
  • 146
  • Use a real webSocket, rather than XHR Polling. webSocket connections do not count toward the http connection limit to the same origin. – jfriend00 Sep 21 '15 at 20:30
  • @jfriend00 aha, thanks! – Sammaye Sep 21 '15 at 20:39
  • 1
    A couple reference articles: [Max parallel http connections in a browser?](http://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser) and [Maximum concurrent connections to the same domain for browsers](http://sgdev-blog.blogspot.com/2014/01/maximum-concurrent-connection-to-same.html) and [HTTP simultaneous connections per host limit… are per tab, browser instance or global?](http://stackoverflow.com/questions/22866552/http-simultaneous-connections-per-host-limit-are-per-tab-browser-instance-or). – jfriend00 Sep 21 '15 at 20:39
  • @jfriend00 if you put that as an answer with some explanation I'll definitely upvote it. I think I am gonna have to use a workaround with cloudflare, my idea of hoping to get around it with xhr is falling apart tbh – Sammaye Sep 21 '15 at 20:41
  • from our testing, websocket is also subjected to the same limit. – Phuah Yee Keat Nov 20 '15 at 11:12
  • @PhuahYeeKeat you can have frames on a websocket which means you can send many types of data down the same websocket and the node.js app can just route the request – Sammaye Oct 28 '16 at 08:16

1 Answers1

21

Use a real webSocket, rather than XHR Polling. webSocket connections do not count toward the http connection limit to the same origin.

There is a separate global limit to how many webSocket connections can be created, but it is a high number (200 in Firefox - not sure what it is exactly in Chrome).

Here are some references on this topic:

kenorb
  • 155,785
  • 88
  • 678
  • 743
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Decided to do this in the end, just made a SSL'd domain outside of cloudflare and decide to say hell to it. I lose some of cloudflares protection but meh this domain serves a single thing – Sammaye Sep 22 '15 at 01:19
  • Cloudflare has websockets now. did you every try to switch to it? – Simon_Weaver Feb 19 '17 at 09:23
  • @Simon_Weaver sorry, only just noticed your comment. I think WS is for their enterprise plan so I have not yet – Sammaye Sep 19 '17 at 21:17
  • It’s for all plans but at different levels of service. I’m on the $20 plan and it works fine – Simon_Weaver Sep 30 '17 at 03:54