2
votes

Here is what our setup looks like:

  • SignalR Server (an ASP.NET MVC application) on windows Server 2012.
  • Sencha HTML5 apps (SignalR clients) on the same server (Windows Server 2012).
  • .NET Windows Service on a Windows Server 2008 R2 server. This also acts as a SignalR client.

We are using the SignalR development build from a couple of weeks ago (1.1.0). Occasionally, we find that the SignalR server loses the connection to the .NET client. Using the latest build allowed us to add client-side logging.

We have a good example of this happening last Thursday (28 Mar 2013 at 6.33 PM).

Client-side log (for the sake of brevity, I have removed any logs that are not important). Note that the Hub class is called "Transmitter".

ChangeState(New connection, Disconnected, Connecting)
WS: wss://www.myURL.com/SignalRServer/signalr/connect?transport=webSockets&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&connectionData=[{"Name":"Transmitter"}]
Auto: Failed to connect to using transport webSockets. System.PlatformNotSupportedException: The WebSocket protocol is not supported on this platform.
   at System.Net.WebSockets.ClientWebSocket..ctor()
   at Microsoft.AspNet.SignalR.Client.Transports.WebSocketTransport.<PerformConnect>d__0.MoveNext()
SSE: GET https://www.myURL.com/SignalRServer/signalr/connect?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,25|1,0|2,0|3,0","M":[{"H":"Transmitter","M":"joined","A":["0e3cd780-9efc-4824-b9a2-bae81b9be17f","27/03/2013 8:16:46 PM"]}]})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,25|1,1|2,0|3,0","M":[{"H":"Transmitter","M":"isLoggedIn","A":[true]}]})
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"0"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
............
............
............
............
............
............
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
Connection Timed-out : Transport Lost Connection 28/03/2013 8:33:14 AM
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connected, Reconnecting)
SSE: GET https://www.myURL.com/SignalRServer/signalr/?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&messageId=B%2C6&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Reconnecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,7","M":[{"H":"Transmitter","M":"rejoined","A":["0e3cd780-9efc-4824-b9a2-bae81b9be17f","28/03/2013 6:33:12 PM"]}]})
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"12"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
............
............

Before the connection times out, everything works as expected - the SignalR server can call .NET client's methods and vice versa. After the connection times out, the .NET client can call server Hub methods, but the server cannot call the .NET client methods.

Other things to note:

  • Note that the connection times out reporting "28/03/2013 8:33:14 AM" as the time. This is different to the times logged in subsequent entries and the time was actually 6:33:14 PM (Australian EST).
  • As can be seen above ServerSentEvents is being used as the SignalR .NET client is on a Windows 2008 server.
  • There is no pattern to the timeout. Sometimes it does not happen for days, other times it happens within a few hours.
  • The timeout is not related to the the machines (both, where the SignalR server or the the SignalR client reside) being rebooted, IIS resets, etc.

Also, this is quite different to momentary connection losses and re-connections, which seem to work as required. An example of a momentary loss in connection is shown below:

SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Connected, Reconnecting)
SSE: GET https://www.myURL.com/SignalRServer/signalr/?transport=serverSentEvents&connectionToken=fsfY8BWv5eiSNuQtHW6wfY6XWDInkrVEn5fyHogSIyapob1BxoZLz0aMO_IuARmd9suam3my3yU0sQOEYMah-ZVj_4idQHXKQmhUKyRFlNgObCWlblCDfXflOq4Fxt8P0&messageId=B%2C1D%7CF%2CE%7CG%2C0%7CH%2C0&connectionData=[{"Name":"Transmitter"}]
ChangeState(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Reconnecting, Connected)
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {"C":"B,2","M":[{"H":"Transmitter","M":"rejoined","A":["00fabf13-eb07-4704-8d43-4d8865a519f0","28/03/2013 4:08:26 PM"]}]})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: initialized)
OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, {"I":"11"})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})
SSE: OnMessage(0e3cd780-9efc-4824-b9a2-bae81b9be17f, Data: {})

What I don't understand is why the momentary connection losses and re-connections seem to work, but the reconnections after a connection time-out do not work.

Is there anything that we can do to address this?

Thanks in advance.

1

1 Answers

1
votes

When the client's Disconnected event is raised it means the connection was removed by the server. After that occurs it's up to the developer to restart the connection.

We do this because keeping state around on the server for a long time is expensive.