Commit adee4c80 authored by Marc Gravell's avatar Marc Gravell

track connection name in the connection fail/restore events

parent 776845f3
......@@ -9,9 +9,9 @@ namespace StackExchange.Redis.Tests
public class ConnectionShutdown : TestBase
{
protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort;
public ConnectionShutdown(ITestOutputHelper output) : base (output) { }
public ConnectionShutdown(ITestOutputHelper output) : base(output) { }
[Fact(Skip="Unfriendly")]
[Fact(Skip = "Unfriendly")]
public async Task ShutdownRaisesConnectionFailedAndRestore()
{
using (var conn = Create(allowAdmin: true))
......@@ -20,12 +20,12 @@ public async Task ShutdownRaisesConnectionFailedAndRestore()
Stopwatch watch = Stopwatch.StartNew();
conn.ConnectionFailed += (sender, args) =>
{
Log(watch.Elapsed + ": failed: " + EndPointCollection.ToString(args.EndPoint) + "/" + args.ConnectionType);
Log(watch.Elapsed + ": failed: " + EndPointCollection.ToString(args.EndPoint) + "/" + args.ConnectionType + ": " + args.ToString());
Interlocked.Increment(ref failed);
};
conn.ConnectionRestored += (sender, args) =>
{
Log(watch.Elapsed + ": restored: " + EndPointCollection.ToString(args.EndPoint) + "/" + args.ConnectionType);
Log(watch.Elapsed + ": restored: " + EndPointCollection.ToString(args.EndPoint) + "/" + args.ConnectionType + ": " + args.ToString());
Interlocked.Increment(ref restored);
};
var db = conn.GetDatabase();
......
......@@ -11,7 +11,7 @@ public sealed class ConnectionFailedEventArgs : EventArgs, ICompletable
{
private readonly EventHandler<ConnectionFailedEventArgs> handler;
private readonly object sender;
internal ConnectionFailedEventArgs(EventHandler<ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception)
internal ConnectionFailedEventArgs(EventHandler<ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, string physicalName)
{
this.handler = handler;
this.sender = sender;
......@@ -19,8 +19,11 @@ internal ConnectionFailedEventArgs(EventHandler<ConnectionFailedEventArgs> handl
ConnectionType = connectionType;
Exception = exception;
FailureType = failureType;
_physicalName = physicalName ?? GetType().Name;
}
private readonly string _physicalName;
/// <summary>
/// Gets the connection-type of the failing connection
/// </summary>
......
......@@ -126,14 +126,14 @@ internal static string TryGetAzureRoleInstanceIdNoThrow()
/// </summary>
public string Configuration => RawConfig.ToString();
internal void OnConnectionFailed(EndPoint endpoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, bool reconfigure)
internal void OnConnectionFailed(EndPoint endpoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, bool reconfigure, string physicalName)
{
if (_isDisposed) return;
var handler = ConnectionFailed;
if (handler != null)
{
UnprocessableCompletionManager.CompleteSyncOrAsync(
new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, failureType, exception)
new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, failureType, exception, physicalName)
);
}
if (reconfigure)
......@@ -161,14 +161,14 @@ internal void OnInternalError(Exception exception, EndPoint endpoint = null, Con
}
}
internal void OnConnectionRestored(EndPoint endpoint, ConnectionType connectionType)
internal void OnConnectionRestored(EndPoint endpoint, ConnectionType connectionType, string physicalName)
{
if (_isDisposed) return;
var handler = ConnectionRestored;
if (handler != null)
{
UnprocessableCompletionManager.CompleteSyncOrAsync(
new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, ConnectionFailureType.None, null)
new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, ConnectionFailureType.None, null, physicalName)
);
}
ReconfigureIfNeeded(endpoint, false, "connection restored");
......
......@@ -306,7 +306,7 @@ internal void OnConnectionFailed(PhysicalConnection connection, ConnectionFailur
LastException = innerException;
reportNextFailure = false; // until it is restored
var endpoint = ServerEndPoint.EndPoint;
Multiplexer.OnConnectionFailed(endpoint, ConnectionType, failureType, innerException, reconfigureNextFailure);
Multiplexer.OnConnectionFailed(endpoint, ConnectionType, failureType, innerException, reconfigureNextFailure, connection?.ToString());
}
}
......
......@@ -491,7 +491,7 @@ internal void OnFullyEstablished(PhysicalConnection connection)
{
Multiplexer.ResendSubscriptions(this);
}
Multiplexer.OnConnectionRestored(EndPoint, bridge.ConnectionType);
Multiplexer.OnConnectionRestored(EndPoint, bridge.ConnectionType, connection?.ToString());
}
}
catch (Exception ex)
......
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