Reputation: 597
Here is what our setup looks like:
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:
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.
Upvotes: 2
Views: 2746
Reputation: 38864
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.
Upvotes: 1