2
votes

I'm using signalR 2.2.1. When the IIS apppool recycles, if there's an open connection, the client tries forever to reconnect (with the same ConnectionId).

A sample of the SignalR client log (for every reconnect attempt):

SignalR: webSockets reconnecting.

SignalR: Connecting to websocket endpoint 'wss://IP/hub/signalr/reconnect?transport=webSockets&groupsToken=8FWHT%2FO774vZYA7IYz8%2F%2FX9zMLswzG98KhGbM83kK5xh%2BVVbqQPv1wQYQWvzTygSQHj9QsDyoHL1U8eQ1fV18QQQ%2FZqRewQEpU4rkRZRE0CE%2B2oDk9RQghCT%2BxlV0KFcl%2FUpuepwX0E5w4xhSScH%2BFkxFvL4vtPIpwYVzInIaW%2BICRWRHrNfjKm9RLiC3a%2F3jcYi1AUeFBJsDnY%2F9bZBrA%3D%3D&messageId=d-C69C65D6-H%2C0%7CI%2C0%7CJ%2C4%7CK%2C0%7CL%2C0%7CM%2C0&clientProtocol=1.5&connectionToken=%2FivgB%2Bcy%2FE1%2B%2BTFj5eCqTEZNzr%2FVuIzdJQVbUypK1YjrZur80uPbufYxGT%2BDC%2FWhsHXZJgUpkI2IyJ8Y8wnuOEAID%2F9kOnSyllFpCQHDN6VRTdMEaU%2F0Kdh4yX2vqKh%2F&connectionData=%5B%7B%22name%22%3A%22hub%22%7D%5D&tid=0'.

SignalR: Closing the Websocket.

SignalR: Websocket opened.

SignalR: Unclean disconnect from websocket: [no reason given].

I did a workaround - when reconnected callback is being called - to stop and start the connection (just start won't work):

    $.connection.hub.reconnected(function() {
        console.log("reconnected");
        $.connection.hub.stop();
        $.connection.hub.start();
    });

But then re connection is being handled by me, and I guess that's not a good idea.

Any other ideas?

1
Is your website authenticated? You may need to pin your machine key if so - thab
@thab It's part of a WCF service (IIS web application) under (child of) web application, The web application is authenticated and has a valid machine key, the service is not, but it gets the authentication from the parent. is that also can bring up this issue? - Programmer
So you have a fixed machine key then do you? (ASP.NET's default is to regenerate a new one each time you restart your app). All authentication will be thrown out because the cookie was signed with a now-invalid machine key. - thab
Yes I did. it still happens. - Programmer
Do you have to log in again after recycling? Basically this should work fine... Do you override the server side onReconnect for the hub? - thab

1 Answers

2
votes

After a series of diagnosis attempts in the comments above:

Try commenting out the OnReconnect method in the Hub. As a general rule, I wouldn't recommend overriding onReconnect - there are very few real reasons why you need it, the only one I can think of might be server-side logging of a reconnect.

In the life-cycle of a Signalr connection, reconnect typically happens when SignalR recovers without any loss of messages - in which case you don't actually need to do anything. There are some other situations where reconnect may occur and you need some sort of recovery, but they're mostly SignalR architectures that I wouldn't recommend (two nodes sharing the same URL and machine-key, but on different backplanes).