Skip to content

C# Client - Always check for valid reconnect window before making a request in clients #2629

Closed
NTaylorMullen opened this Issue Oct 14, 2013 · 6 comments

2 participants

@NTaylorMullen

Before the client makes any request (after connecting) it should always check to ensure that the time since the server was last heard from (the last successful result from the server) is less than the configured disconnect threshold.

This is in addition to the keep alive check that runs in forever transports. It helps address scenarios where the client makes requests although the server has already disconnect them, e.g. when a browser is suspended on a mobile device.

This is the C# version of #2513.

#2528

@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 18, 2013
@NTaylorMullen NTaylorMullen Modified KeepAlive to utilize a LastMessageAt property.
- Also modified existing tests that relied on the LastKeepAlive property to now rely on LastMessageAt.
- LastMessageAt can now be used by LongPolling for message monitoring purposes.

#2629
a5f66b5
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 18, 2013
@NTaylorMullen NTaylorMullen Added a ReconnectWindow to the connection object.
- ReconnectWindows are used to ensure that connections do not attempt to reconnect after extended periods of time.

Conflicts:
	src/Microsoft.AspNet.SignalR.Client/Connection.cs
	src/Microsoft.AspNet.SignalR.Client/IConnection.cs
	src/Microsoft.AspNet.SignalR.Client/Transports/TransportHelper.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Client/ConnectionFacts.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Server/Connections/ConnectionFacts.cs

#2629
697ce70
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 18, 2013
@NTaylorMullen NTaylorMullen Added a default beat interval for the HeartbeatMonitor in the situati…
…ons where KeepAlive is disabled on the server.

- Also fixed some tests to properly return transports with valid SupportsKeepAlive values.

Initialize the lastActiveAt flag to ensure that there's no race between a transport start and the flag set.

- This is to ensure we don't pre-emptively close connections on reconnect.

Conflicts:
	src/Microsoft.AspNet.SignalR.Client/Connection.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Client/KeepAliveFacts.cs

#2629
c3dd58d
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 18, 2013
@NTaylorMullen NTaylorMullen Added a test to verify that ReconnectWindows work appropriately.
Fixed tests to abide by new heartbeat timer and the last message at value.

Fixed some more keep alive fact tests since the heartbeat monitor now requires to be started before beat works for keep alive.

Conflicts:
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Client/KeepAliveFacts.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Server/Connections/ConnectionFacts.cs

#2629
4fc1795
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 18, 2013
@NTaylorMullen NTaylorMullen Added a test to verify that ReconnectWindows work appropriately.
Fixed tests to abide by new heartbeat timer and the last message at value.

Fixed some more keep alive fact tests since the heartbeat monitor now requires to be started before beat works for keep alive.

Conflicts:
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Client/KeepAliveFacts.cs
	tests/Microsoft.AspNet.SignalR.FunctionalTests/Server/Connections/ConnectionFacts.cs

#2629
b67eebe
@gustavo-armenta

I don't see reconnect window terminating the connection because markActive executes before verifyReconnect

REPRO
1. Use branch 2629
2. Run Microsoft.AspNet.SignalR.Samples
3. Run Microsoft.AspNet.SignalR.Client.WindowsStoreCSharp.Samples
4. Switch to another app (WinStore app suspends after some seconds)
5. Wait 3 minutes and stop web server
6. Wait 10 seconds and switch to WinStore app

01:26:50.0241117 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:26:52.2582397 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:26:54.4933688 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:26:56.7265005 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:32:21.2202935 - 9ee4709d-fca2-455d-88fb-519ea1062596 - LP: OnMessage({"C":"d-90FE32D2-B,1|C,2|D,3|E,0","M":[]})
01:32:21.2202935 - 9ee4709d-fca2-455d-88fb-519ea1062596 - MarkLastMessage
01:32:21.2202935 - 9ee4709d-fca2-455d-88fb-519ea1062596 - LP Poll: http://localhost:40476/signalr/poll
01:32:21.5443300 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:32:23.2294080 - 9ee4709d-fca2-455d-88fb-519ea1062596 - verifyReconnect
01:32:23.2294080 - 9ee4709d-fca2-455d-88fb-519ea1062596 - ChangeState(Connected, Reconnecting)
01:32:23.2344080 - 9ee4709d-fca2-455d-88fb-519ea1062596 - OnError(System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 127.0.0.1:40476
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception))
01:32:23.7744805 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:32:25.2435272 - 9ee4709d-fca2-455d-88fb-519ea1062596 - LP Reconnect: http://localhost:40476/signalr/reconnect
01:32:26.0096022 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive
01:32:27.2496418 - 9ee4709d-fca2-455d-88fb-519ea1062596 - verifyReconnect
01:32:27.2496418 - 9ee4709d-fca2-455d-88fb-519ea1062596 - OnError(System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 127.0.0.1:40476
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception))
01:32:28.2406989 - 9ee4709d-fca2-455d-88fb-519ea1062596 - markActive

@NTaylorMullen

@gustavo-armenta good find, it's not a consistent repro but I understand what's going on. This issue also exists in the dev branch.

Essentially what's happening is that the transport is attempting to reconnect but waiting around 3s prior to running reconnect code because we delay it to ensure that reconnects do not happen in quick succession. During that 3s wait period the markActive event MAY occur which then negates the verifyReconnect check. I'll work on a fix.

@NTaylorMullen NTaylorMullen added a commit that referenced this issue Oct 31, 2013
@NTaylorMullen NTaylorMullen Added extra verifyReconnect checks to ensure that if the client goes …
…to sleep that we do not mark it active prior to trying to reconnect.

- Also added a test to verify that this scenario is covered.

#2629
c23520d
@gustavo-armenta

@NTaylorMullen
I still see this issue

17:01:48.1290097 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - markActive
17:01:50.3640414 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - markActive
17:01:52.5971935 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - markActive
17:01:54.8322850 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - markActive
17:05:13.9621660 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - LP: OnMessage({"C":"d-31DE627-B,1|C,2|D,3|E,0","M":[]})
17:05:13.9621660 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - MarkLastMessage
17:05:13.9621660 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - LP Poll: http://localhost:40476/signalr/poll
17:05:15.1201725 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - markActive
17:05:15.9681297 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - verifyReconnect
17:05:15.9681297 - ddd6f4a3-fb1c-4c5e-95af-99f5a9ba58de - ChangeState(Connected, Reconnecting)
@NTaylorMullen NTaylorMullen was assigned Nov 4, 2013
@NTaylorMullen

@gustavo-armenta what browser are you using

@NTaylorMullen

Waiting on 2.0.2 version to be completed to work on this.

@NTaylorMullen NTaylorMullen added a commit that referenced this issue Nov 13, 2013
@NTaylorMullen NTaylorMullen Added VerifyReconnect steps to the MarkActive function of connection.
- Added a test to verify the behavior
- Also fixed an issue that caused "Stop" to throw if the connection had not already been started.

#2629
7c0b432
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Nov 13, 2013
@NTaylorMullen NTaylorMullen Fixed tests. b343174
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Nov 13, 2013
@NTaylorMullen NTaylorMullen Added VerifyReconnect steps to the MarkActive function of connection.
- Added a test to verify the behavior
- Also fixed an issue that caused "Stop" to throw if the connection had not already been started.

#2629
5f4d2b3
@NTaylorMullen NTaylorMullen added a commit that referenced this issue Nov 13, 2013
@NTaylorMullen NTaylorMullen Fixed tests. 0d35899
@gustavo-armenta

suspended winstore c# sample for longer than one minute, when reactivated the app it disconnects as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.