Permalink
Browse files

Modified transport connect timeout so that it doesn't add over multip…

…le negotiate requests

#2738
  • Loading branch information...
1 parent 223fc0e commit e9bef04f8ff011f98de27332335a1e3aba54443f @abnanda1 abnanda1 committed Dec 7, 2013
@@ -42,6 +42,9 @@ public class Connection : IConnection, IDisposable
// The amount of time the client should attempt to reconnect before stopping.
private TimeSpan _disconnectTimeout;
+ // The amount of time a transport will wait (while connecting) before failing.
+ private TimeSpan _totalTransportConnectTimeout;
+
// Provides a way to cancel the the timeout that stops a reconnect cycle
private IDisposable _disconnectTimeoutOperation;
@@ -176,6 +179,7 @@ public Connection(string url, string queryString)
TraceWriter = new DebugTextWriter();
Headers = new HeaderDictionary(this);
TransportConnectTimeout = TimeSpan.Zero;
+ _totalTransportConnectTimeout = TimeSpan.Zero;
// Current client protocol
Protocol = new Version(1, 3);
@@ -187,6 +191,18 @@ public Connection(string url, string queryString)
/// </summary>
public TimeSpan TransportConnectTimeout { get; set; }
+ /// <summary>
+ /// The amount of time a transport will wait (while connecting) before failing.
+ /// This is the total vaue obtained by adding the server's configuration value and the timeout specified by the user
+ /// </summary>
+ TimeSpan IConnection.TotalTransportConnectTimeout
+ {
+ get
+ {
+ return _totalTransportConnectTimeout;
+ }
+ }
+
public Version Protocol { get; set; }
/// <summary>
@@ -446,7 +462,7 @@ private Task Negotiate(IClientTransport transport)
ConnectionId = negotiationResponse.ConnectionId;
ConnectionToken = negotiationResponse.ConnectionToken;
_disconnectTimeout = TimeSpan.FromSeconds(negotiationResponse.DisconnectTimeout);
- TransportConnectTimeout = TransportConnectTimeout + TimeSpan.FromSeconds(negotiationResponse.TransportConnectTimeout);
+ _totalTransportConnectTimeout = TransportConnectTimeout + TimeSpan.FromSeconds(negotiationResponse.TransportConnectTimeout);
// Default the beat interval to be 5 seconds in case keep alive is disabled.
var beatInterval = TimeSpan.FromSeconds(5);
@@ -624,6 +640,7 @@ private void Disconnect()
Trace(TraceLevels.Events, "Closed");
// Clear the state for this connection
+ _totalTransportConnectTimeout = TimeSpan.Zero;
ConnectionId = null;
ConnectionToken = null;
GroupsToken = null;
@@ -21,6 +21,7 @@ public interface IConnection
{
Version Protocol { get; set; }
TimeSpan TransportConnectTimeout { get; set; }
+ TimeSpan TotalTransportConnectTimeout { get; }
TimeSpan ReconnectWindow { get; set; }
KeepAliveData KeepAliveData { get; set; }
string MessageId { get; set; }
@@ -66,7 +66,7 @@ public Task Start(IConnection connection, string connectionData, CancellationTok
throw new ArgumentNullException("connection");
}
- var initializeHandler = new TransportInitializationHandler(connection.TransportConnectTimeout, disconnectToken);
+ var initializeHandler = new TransportInitializationHandler(connection.TotalTransportConnectTimeout, disconnectToken);
OnStart(connection, connectionData, disconnectToken, initializeHandler);

0 comments on commit e9bef04

Please sign in to comment.