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