signalr not working on specific isp networks

2019-04-20 23:00发布

问题:

I'm using ASP.NET MVC 4 and SignalR 2.1.1. My website works great for most users in all browsers, but there is an error that only occurs for certain user on specific isp-networks.

The error is this:

The connection to ws://domain.com/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=78ZpJ007jmlLSBbVzDVbfpYahHsveD3x8%2Bc5PC9h%2FgeOz5zNgE8SaKWaQAasGNLe%2BvJeI6ux6IqW0E8WQWqP6Ps%2FXjc8WPbG7G47oHSxRSx7nVj0leVa1DdXzEXnLQ%2BA&connectionData=%5B%7B%22name%22%3A%22homehub%22%7D%5D&tid=4 was interrupted while the page was loading.

For the same users receiving this error, logging in the internet using a different network (while same browser / computer / cellphone) fixes the problem.

Up until now I only saw questions about this error that points the problem to the browser, however in my case, using the same browser with a different network fixes the problem.

Any chance any of you knows how to fix this?

UPDATE 1: I noticed that client methods actually works, it's the server methods that don't work.

What do I mean?:

I have a list of online users, and upon user entering & exiting the site, a signalr client method that updates the list of usernames is called:

hub.client.addOnlineMember = function (member) {
    var newMember = addMember(member);
    memberList.append(newMember);
};
hub.client.removeOnlineMember = function (member) {
    var newMemberId = '#' + member;
    $(memberListName + ' ' + newMemberId).remove();
};

However when trying to load messages from the server, it's functions don't work:

$('#LoadMore').click(function () {
        hub.server.loadTopics(page);
    });

UPDATE 2: I added logging:

$.connection.hub.logging = true;

Here are the findings:

The connection to ws://domain.com/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=rR8%2BSK%2BC%2FtuzPqIGKgPrUNORzBz2kP0WUmXJsURP70Zsj6RK1fOi5tUN1UGEQPntGwoEvwinMkPCXRTyliLwzfLoOBl%2BkCWoBAkAqIFYaDVk3X1MG8dQERl8Or%2F4%2Filp&connectionData=%5B%7B%22name%22%3A%22hub%22%7D%5D&tid=6 was interrupted while the page was loading. jquery.signalr-2.1.1.min.js:8
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/ jquery-2.1.1.min.js:4
"[16:21:50] SignalR: Stopping connection." jquery.signalr-2.1.1.min.js:8
"[16:21:50] SignalR: Closing the Websocket." jquery.signalr-2.1.1.min.js:8
no element found abort:1
"[16:21:50] SignalR: Fired ajax abort async = false." jquery.signalr-2.1.1.min.js:8
"[16:21:50] SignalR: Stopping the monitoring of the keep alive." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: Client subscribed to hub 'hub'." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22hub%22%7D%5D'." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: Connecting to websocket endpoint 'ws://domain.com/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=bkg5ksXTUdzl9GrShmLqEyUbeG9SMDBaiccbH2prQ4t1mPmoOutKqj9gvgkd9vveTnIKhK0cMHYZ8NOrS4pemaLmwOb5TmNJzGEiPAUXrknuIhxtUSqmNmL255MIFdwc&connectionData=%5B%7B%22name%22%3A%22hub%22%7D%5D&tid=2'." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: Websocket opened." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: webSockets transport selected. Initiating start request." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: The start request succeeded. Transitioning to the connected state." jquery.signalr-2.1.1.min.js:8
"[16:21:51] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000." jquery.signalr-2.1.1.min.js:8
"[16:23:05] SignalR: Triggering client hub event 'addOnlineMember' on hub 'hub'." jquery.signalr-2.1.1.min.js:8
"[16:23:25] SignalR: Triggering client hub event 'removeOnlineMember' on hub 'hub'." jquery.signalr-2.1.1.min.js:8
"[16:23:42] SignalR: Invoking hub.LoadTopics" jquery.signalr-2.1.1.min.js:8

As you can see, client methods works great. Server method is being invoked but nothing happens.

Logging signalr on a working isp network:

"[17:03:40] SignalR: Invoking hub.LoadTopics" jquery.signalr-2.1.1.min.js:8
"[17:03:41] SignalR: Triggering client hub event 'addTopicToHome' on hub 'hub'." jquery.signalr-2.1.1.min.js:8
"[17:03:41] SignalR: Triggering client hub event 'incrementPage' on hub 'hub'." jquery.signalr-2.1.1.min.js:8
"[17:03:41] SignalR: Invoked hub.LoadTopics" jquery.signalr-2.1.1.min.js:8

UPDATE 3:

Upon uploading my project to an IIS 7.5 server, the code works for all ISP networks. Seeing as IIS 7.5 does not support Websockets, protocols such as server-sent-events, long polling and forever frame (depends on the browser) are initiated successfully. However, I don't know the reason why the IIS 8 server is not initiating a working protocol upon realizing websockets don't work, it's what signalr does, isn't it?

I made contact with my hosting provider, they think the problem has something to do with an unsupported SSL key on the server. This SSL issue still hasn't been fixed by them so there's no way to be sure that's really the problem. Do you think this might be it?

Anyway, still no success in finding an answer.. please help.

回答1:

Okay its been so long and I was hoping to get help by now, but never mind I mannaged it.

First:

The guys at signalr's channel in Jabbr suggested me to try surfing the website using SSL in hopes it would solve the problem. I'm afraid I did not have the chance to check that :( But in case any of you meets the same issue and gets to use SSL approach to solve it, I would deffinitly love to here about it!

And to my answer:

I am taking the user IP and testing if it's in any of the problematic ISP subnets. If it is, I'm passing my view a parameter, lets say: bool disableWebsockets = True/False; If its true, I'm passing signalr a list of transport protocols that does not include websockets. If false - the list does include websockets.

That's it.

function signalrTransportList(wsState) {
    if (disableWebsockets == "False") {
        var list = ['webSockets', 'serverSentEvents', 'longPolling', 'foreverFrame'];
    }
    else {
        var list = ['serverSentEvents', 'longPolling', 'foreverFrame'];
    }

    return list;
}

...
...

$.connection.hub.start({ transport: signalrTransportList(wsTransport) })