Commit 0c7f531a authored by Marc Gravell's avatar Marc Gravell

moar logging on CheckForStaleConnections

parent 83a046eb
...@@ -158,11 +158,16 @@ public void Flush() ...@@ -158,11 +158,16 @@ public void Flush()
Interlocked.Exchange(ref lastWriteTickCount, Environment.TickCount); Interlocked.Exchange(ref lastWriteTickCount, Environment.TickCount);
} }
} }
public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null) public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
{
SocketManager.ManagerState mgrState = SocketManager.ManagerState.CheckForStaleConnections;
RecordConnectionFailed(failureType, ref mgrState, innerException, origin);
}
public void RecordConnectionFailed(ConnectionFailureType failureType, ref SocketManager.ManagerState managerState, Exception innerException = null, [CallerMemberName] string origin = null)
{ {
IdentifyFailureType(innerException, ref failureType); IdentifyFailureType(innerException, ref failureType);
managerState = SocketManager.ManagerState.RecordConnectionFailed_OnInternalError;
if (failureType == ConnectionFailureType.InternalFailure) OnInternalError(innerException, origin); if (failureType == ConnectionFailureType.InternalFailure) OnInternalError(innerException, origin);
// stop anything new coming in... // stop anything new coming in...
...@@ -170,6 +175,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -170,6 +175,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
bool isCurrent; bool isCurrent;
PhysicalBridge.State oldState; PhysicalBridge.State oldState;
int @in = -1, ar = -1; int @in = -1, ar = -1;
managerState = SocketManager.ManagerState.RecordConnectionFailed_OnDisconnected;
bridge.OnDisconnected(failureType, this, out isCurrent, out oldState); bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);
if(oldState == PhysicalBridge.State.ConnectedEstablished) if(oldState == PhysicalBridge.State.ConnectedEstablished)
{ {
...@@ -182,6 +188,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -182,6 +188,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0) if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
{ {
managerState = SocketManager.ManagerState.RecordConnectionFailed_ReportFailure;
int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount), int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount),
lastBeat = Thread.VolatileRead(ref lastBeatTickCount); lastBeat = Thread.VolatileRead(ref lastBeatTickCount);
int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount); int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount);
...@@ -232,10 +239,12 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -232,10 +239,12 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
ex.Data["Redis-" + kv.Item1] = kv.Item2; ex.Data["Redis-" + kv.Item1] = kv.Item2;
} }
managerState = SocketManager.ManagerState.RecordConnectionFailed_OnConnectionFailed;
bridge.OnConnectionFailed(this, failureType, ex); bridge.OnConnectionFailed(this, failureType, ex);
} }
// cleanup // cleanup
managerState = SocketManager.ManagerState.RecordConnectionFailed_FailOutstanding;
lock (outstanding) lock (outstanding)
{ {
bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count); bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
...@@ -249,6 +258,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception ...@@ -249,6 +258,7 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, Exception
} }
// burn the socket // burn the socket
managerState = SocketManager.ManagerState.RecordConnectionFailed_ShutdownSocket;
var socketManager = multiplexer.SocketManager; var socketManager = multiplexer.SocketManager;
if (socketManager != null) socketManager.Shutdown(socketToken); if (socketManager != null) socketManager.Shutdown(socketToken);
} }
...@@ -1045,7 +1055,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count) ...@@ -1045,7 +1055,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count)
partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite); partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite);
public void CheckForStaleConnection() public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
{ {
int firstUnansweredWrite; int firstUnansweredWrite;
firstUnansweredWrite = Thread.VolatileRead(ref firstUnansweredWriteTickCount); firstUnansweredWrite = Thread.VolatileRead(ref firstUnansweredWriteTickCount);
...@@ -1056,7 +1066,7 @@ public void CheckForStaleConnection() ...@@ -1056,7 +1066,7 @@ public void CheckForStaleConnection()
if (firstUnansweredWrite != 0 && (now - firstUnansweredWrite) > this.multiplexer.RawConfig.ResponseTimeout) if (firstUnansweredWrite != 0 && (now - firstUnansweredWrite) > this.multiplexer.RawConfig.ResponseTimeout)
{ {
this.RecordConnectionFailed(ConnectionFailureType.SocketFailure, origin: "CheckForStaleConnection"); this.RecordConnectionFailed(ConnectionFailureType.SocketFailure, ref managerState, origin: "CheckForStaleConnection");
} }
} }
} }
......
...@@ -158,13 +158,23 @@ internal enum ManagerState ...@@ -158,13 +158,23 @@ internal enum ManagerState
ExecuteSelect, ExecuteSelect,
ExecuteSelectComplete, ExecuteSelectComplete,
CheckForStaleConnections, CheckForStaleConnections,
RecordConnectionFailed_OnInternalError,
RecordConnectionFailed_OnDisconnected,
RecordConnectionFailed_ReportFailure,
RecordConnectionFailed_OnConnectionFailed,
RecordConnectionFailed_FailOutstanding,
RecordConnectionFailed_ShutdownSocket,
CheckForStaleConnectionsDone,
EnqueueRead, EnqueueRead,
EnqueueError, EnqueueError,
EnqueueReadFallback, EnqueueReadFallback,
RequestAssistance, RequestAssistance,
ProcessQueues, ProcessQueues,
ProcessReadQueue, ProcessReadQueue,
ProcessErrorQueue, ProcessErrorQueue,
} }
internal ManagerState State internal ManagerState State
{ {
...@@ -294,9 +304,10 @@ private void ReadImpl() ...@@ -294,9 +304,10 @@ private void ReadImpl()
} }
else else
{ {
s.CheckForStaleConnection(); s.CheckForStaleConnection(ref managerState);
} }
} }
managerState = ManagerState.CheckForStaleConnectionsDone;
} }
else else
{ {
......
...@@ -40,7 +40,7 @@ internal partial interface ISocketCallback ...@@ -40,7 +40,7 @@ internal partial interface ISocketCallback
void StartReading(); void StartReading();
// check for write-read timeout // check for write-read timeout
void CheckForStaleConnection(); void CheckForStaleConnection(ref SocketManager.ManagerState state);
bool IsDataAvailable { get; } bool IsDataAvailable { get; }
} }
......
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