SignalR icon indicating copy to clipboard operation
SignalR copied to clipboard

Limited unique connections (opened tabs) IIS8, Windows8

Open Lionberg opened this issue 14 years ago • 17 comments

It is omposible to use SignalR, when several tabs opened with unique ids assigned to each tab (see. http://stackoverflow.com/questions/10426163/when-signalr-made-8-10-connections-at-a-time-live-chat-doesnt-work).

But. there is a workaround I described in this stackoverflow issue. The idea is to overwrite connectionid in order, that every opened tab would have the same connection id: thus, logicaly, in my particular case, there is no reason to have unique ids for each tab, 'cos each tab is opened by one MyApplicationUserId.

Anyway, you noticed in stackoverflow (see http://stackoverflow.com/questions/11522090/signalr-how-is-a-duplicate-connection-id-handled ), that connectionid must be unique. And they say, that IConnectionIdGenerator will be removed in an upcomming release.

So, this is a kind of blind alley. I must use unique ids, but I cannot use SignalR with several browser tabs opened.

Thank you. Dmitry.

Lionberg avatar Oct 23 '12 11:10 Lionberg

That's by design and it's not even a windows 8 problem. It's a with browsers in general. Using the same connection id doesn't solve anything, it'll just give you ping pong behavior where connections will bounce each other off forever.

davidfowl avatar Oct 23 '12 16:10 davidfowl

But, for instance, if I open my facebook account in 100 tabs in one browser, I will receive, say, message chat notification for all tabs. And I need the same from SignalR. Can it be done?

Lionberg avatar Oct 23 '12 16:10 Lionberg

It's a browser limitation. To work around it facebook uses subdomains. Each new tab you open yields a new connection to a different sub domain. Take a look at your network tab and see how it works.

davidfowl avatar Oct 23 '12 17:10 davidfowl

Does the same limit apply for websocket connections?

akoeplinger avatar Oct 23 '12 17:10 akoeplinger

akoeplinger, as far as I tried -- no, it doesn't. Before I came to SignalR, I implemented websockets, but with no help of any libraries. I did handshakes according the websocket protocol, and opened connection from client. but there are different issues with websockets. For example, several browsers close socket, when you open a new tab. (i did worker background to reconect if connection closed).

David, thank you. That is good workaround.

Lionberg avatar Oct 23 '12 18:10 Lionberg

I can verify that this ping pong behavior is indeed the case for long polling, server sent events, and websockets. This pretty much defeats the purpose of using SignalR so obviously this is not a solution :)

It is unfortunate but it does seem that the solution I came up with elsewhere to make a separate ajax call after SignalR connects and register the connectionId in the database next to the session Id, is the best option.

AlexAllocated avatar Oct 24 '12 07:10 AlexAllocated

It's not a SignalR limitation, it's a browser limitation and there's no real way to fix it.

davidfowl avatar Oct 24 '12 07:10 davidfowl

I am aware of that. I'm not blaming SignalR at all. I'm just pointing out for future visitors that the same browser restrictions apply no matter which type of connection SignalR attempts to use in case anyone was thinking of trying different transports. The browser does not discriminate between a plain request, event stream, or a websocket. They all count toward the browser's upper single domain connection limit.

AlexAllocated avatar Oct 24 '12 15:10 AlexAllocated

@Chevex: WebSocket connections count towards a different (much higher) limit. Take a look at slide 35 in this presentation: http://media.blackhat.com/bh-us-12/Briefings/Shekyan/BH_US_12_Shekyan_Toukharian_Hacking_Websocket_Slides.pdf

akoeplinger avatar Oct 28 '12 20:10 akoeplinger

@akoeplinger Is this true for all current browsers? I was unable to find any trustworthy information related to Websocket and their connection limits per domain.

nmehlei avatar Aug 22 '13 12:08 nmehlei

At least IE and FF have clear documentation about their limits: FF: 200 connections (total): https://developer.mozilla.org/en-US/docs/WebSockets#Gecko_notes IE: 6 connections (per host): http://msdn.microsoft.com/en-us/library/ee330736(v=vs.85).aspx#websocket_maxconn

I don't know about the other browsers though.

akoeplinger avatar Aug 22 '13 18:08 akoeplinger

I don't know the explicit limit for Chrome but I do know there is one because we hit it at my place of work and it caused all sorts of issues. I got around it using HTML5 localstorage to talk to other tabs that are open and coordinating with one single tab that maintained the websocket connection. That tab would then send data to other tabs via local storage.

I wrote a blog post on this issue a while back: http://codetunnel.com/blog/post/cannot-have-many-tabs-open-with-signalr

@akoeplinger I know you say they count toward a higher limit but when we started having issues employees were only opening approximately 7 or 8 tabs and it was extremely clear that the persistent connections were blocking normal HTTP requests from being made to the same domain. It wouldn't even pull down resource files like CSS or JavaScript if too many persistent websocket connections were open to the same domain. It's been over a year so that behavior may have changed; If I get some time today I'll put together a sample app and try to duplicate the issue.

AlexAllocated avatar Aug 22 '13 19:08 AlexAllocated

@Chevex Are you sure the clients were connected using WebSockets? The other HTTP-based transports would of course eat pretty quickly into the usual ~6 concurrent HTTP connections limit. To test this, visit http://www.websocket.org/echo.html and see if it still connects after opening many tabs.

Interestingly, this also seems to work in IE10, which (when trusting the documentation) shouldn't be possible because MSDN says the limit is 6 connections "to the same host". Even more interesting in relation to this is #1744, which mentions that after opening 6 tabs via window.open() a SCRIPT5022 error occurs, which I could easily reproduce on the Echo test site above. This looks like a security measure so a single page (and apparently other pages opened by the page) can't create thousands of WS connections and overwhelm the server, but when the user himself opens a new tab or window the limit doesn't apply.

FF in contrast applies its limit cross-process and cross-domain, so it doesn't care if tabs were opened by a script or by the user.

I read your blog post and StackOverflow answer and while the localStorage solution sounds nifty, I feel that a much simpler workaround for the HTTP-based transports would be to connect to a random subdomain e.g. chat576.example.com for SignalR and make an UrlRewrite rule on the server that rewrites all chat*.example.com requests to the root website. This way, the browser would think it is connecting to different domains when in reality it isn't. Or do I miss something here?

akoeplinger avatar Aug 23 '13 17:08 akoeplinger

The subdomain solution is a popular one, yes. I was just unsure how to do the rewrite rule so I went with the localstorage. The subdomain solution certainly has the advantage of requiring very little work on the client and would work in pre-html5 browsers as well. If you figure out how to do the rewrite rule please update because I would like to know how you did it.

AlexAllocated avatar Aug 23 '13 18:08 AlexAllocated

I guess one way if you have multiple sites running on the same server and can't make them all have IIS bindings with no hostnames is to add say about 25 hostnames like this:

sr1.codetunnel.com
sr2.codetunnel.com
sr3.codetunnel.com
sr4.codetunnel.com
sr5.codetunnel.com
sr6.codetunnel.com
sr7.codetunnel.com
sr8.codetunnel.com
sr9.codetunnel.com
sr10.codetunnel.com
sr11.codetunnel.com
sr12.codetunnel.com
sr13.codetunnel.com
sr14.codetunnel.com
sr15.codetunnel.com
sr16.codetunnel.com
sr17.codetunnel.com
sr18.codetunnel.com
sr19.codetunnel.com
sr20.codetunnel.com
sr21.codetunnel.com
sr22.codetunnel.com
sr23.codetunnel.com
sr24.codetunnel.com
sr25.codetunnel.com

Since IIS can't do wildcard bindings you could do that and then just have each tab pick a random number between 1 and 25 for the URL to connect to.

var subNum = Math.floor((Math.random()*25)+1);
var url = 'sr' + subNum + '.codetunnel.com';

AlexAllocated avatar Aug 23 '13 18:08 AlexAllocated

Want to share my solution based on localStorage

slimjack avatar May 07 '15 11:05 slimjack

What I am not getting here is. let say its the limitation of the browser. But Why is the user running on different browser on different machine not able to browse the URL. They are able to browse only when the spinning(hanging) URL on mine is closed. He is being able to browse the URL immediately after the spinning tab is closed.

gopaldahal avatar Jul 25 '19 09:07 gopaldahal