Commit eee8bd04 authored by DeepakVerma's avatar DeepakVerma

First time ConnectTimeout error when abortonconnect is false

parent 44ace4ef
...@@ -87,6 +87,23 @@ public void SocketFailureError() ...@@ -87,6 +87,23 @@ public void SocketFailureError()
} }
} }
[Test]
public void AbortOnConnectFailFalseConnectTimeoutError()
{
string name, password;
GetAzureCredentials(out name, out password);
var options = new ConfigurationOptions();
options.EndPoints.Add(name + ".redis.cache.windows.net");
options.Ssl = true;
options.ConnectTimeout = 0;
options.Password = password;
using (var muxer = ConnectionMultiplexer.Connect(options))
{
var ex = Assert.Throws<RedisConnectionException>(() => muxer.GetDatabase().Ping());
Assert.That(ex.Message, Does.Contain("ConnectTimeout"));
}
}
[Test] [Test]
public void CheckFailureRecovered() public void CheckFailureRecovered()
{ {
......
...@@ -871,8 +871,12 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul ...@@ -871,8 +871,12 @@ private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> mul
{ {
task.ObserveErrors(); task.ObserveErrors();
if (muxer.RawConfig.AbortOnConnectFail) if (muxer.RawConfig.AbortOnConnectFail)
{ {
throw ExceptionFactory.UnableToConnect("Timeout"); throw ExceptionFactory.UnableToConnect("ConnectTimeout");
}
else
{
muxer.LastException = ExceptionFactory.UnableToConnect("ConnectTimeout");
} }
} }
if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer.failureMessage); if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer.failureMessage);
...@@ -984,6 +988,9 @@ private void OnHeartbeat() ...@@ -984,6 +988,9 @@ private void OnHeartbeat()
return unchecked(Environment.TickCount - VolatileWrapper.Read(ref lastHeartbeatTicks)) / 1000; return unchecked(Environment.TickCount - VolatileWrapper.Read(ref lastHeartbeatTicks)) / 1000;
} }
} }
internal Exception LastException { get; set; }
internal static long LastGlobalHeartbeatSecondsAgo => unchecked(Environment.TickCount - VolatileWrapper.Read(ref lastGlobalHeartbeatTicks)) / 1000; internal static long LastGlobalHeartbeatSecondsAgo => unchecked(Environment.TickCount - VolatileWrapper.Read(ref lastGlobalHeartbeatTicks)) / 1000;
internal CompletionManager UnprocessableCompletionManager => unprocessableCompletionManager; internal CompletionManager UnprocessableCompletionManager => unprocessableCompletionManager;
...@@ -1129,6 +1136,10 @@ public bool Configure(TextWriter log = null) ...@@ -1129,6 +1136,10 @@ public bool Configure(TextWriter log = null)
{ {
throw new TimeoutException(); throw new TimeoutException();
} }
else
{
LastException = new TimeoutException("ConnectTimeout");
}
return false; return false;
} }
return task.Result; return task.Result;
......
...@@ -102,7 +102,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, RedisCommand ...@@ -102,7 +102,7 @@ internal static Exception NoConnectionAvailable(bool includeDetail, RedisCommand
serverSnapshot = new ServerEndPoint[] { server }; serverSnapshot = new ServerEndPoint[] { server };
} }
var innerException = GetServerSnapshotInnerExceptions(serverSnapshot); var innerException = PopulateInnerExceptions(serverSnapshot);
StringBuilder exceptionmessage = new StringBuilder("No connection is available to service this operation: "); StringBuilder exceptionmessage = new StringBuilder("No connection is available to service this operation: ");
exceptionmessage.Append(commandLabel); exceptionmessage.Append(commandLabel);
...@@ -122,11 +122,16 @@ internal static Exception NoConnectionAvailable(bool includeDetail, RedisCommand ...@@ -122,11 +122,16 @@ internal static Exception NoConnectionAvailable(bool includeDetail, RedisCommand
return ex; return ex;
} }
internal static Exception GetServerSnapshotInnerExceptions(ServerEndPoint[] serverSnapshot) internal static Exception PopulateInnerExceptions(ServerEndPoint[] serverSnapshot)
{ {
List<Exception> innerExceptions = new List<Exception>(); List<Exception> innerExceptions = new List<Exception>();
if (serverSnapshot != null) if (serverSnapshot != null)
{ {
if (serverSnapshot.Length > 0 && serverSnapshot[0].Multiplexer.LastException != null)
{
innerExceptions.Add(serverSnapshot[0].Multiplexer.LastException);
}
for (int i = 0; i < serverSnapshot.Length; i++) for (int i = 0; i < serverSnapshot.Length; i++)
{ {
if (serverSnapshot[i].LastException != null) if (serverSnapshot[i].LastException != null)
......
...@@ -101,7 +101,7 @@ internal Exception LastException ...@@ -101,7 +101,7 @@ internal Exception LastException
//check if subscription endpoint has a better lastexception //check if subscription endpoint has a better lastexception
if (tmp2 != null && tmp2.LastException != null) if (tmp2 != null && tmp2.LastException != null)
{ {
if (!tmp2.LastException.Data["Redis-FailureType"].ToString().Equals(ConnectionFailureType.UnableToConnect.ToString())) if (tmp2.LastException.Data.Contains("Redis-FailureType") && !tmp2.LastException.Data["Redis-FailureType"].ToString().Equals(ConnectionFailureType.UnableToConnect.ToString()))
{ {
return tmp2.LastException; return tmp2.LastException;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment