private bool FailMe(Exception e) { lock (failLock) { var fail = (e is IOException) ? e : new IOException("io fail; see inner exception", e); // empty all queues FailQueue(writeQueue, fail); FailQueue(readQueue, fail); counterReadQueue.Reset(); counterWriteQueue.Reset(); // kill the partially sent op (if any) if (currentWriteCopier != null) { currentWriteOp.Task.SetException(fail); currentWriteOp = Data.Empty; currentWriteCopier = null; } // kill the partially read response if (inprogressResponse != null) { inprogressResponse.Dispose(); inprogressResponse = null; } Volatile.Write(ref runMode, MODE_SEND); // mark as dead if policy says so if (failurePolicy.ShouldFail(this)) { IsAlive = false; MarkAsReady(); return(true); } // otherwise reconnect immediately // (when it's our turn again, to be precise) mustReconnect = true; MarkAsReady(); // reconnect from IO thread owner.NeedsIO(this); return(false); } }
private bool FailMe(Exception e) { lock (failLock) { LogTo.Error(e, $"Node {name} has failed during IO."); var fail = (e is IOException) ? e : new IOException("io fail; see inner exception", e); // empty all queues FailQueue(writeQueue, fail); FailQueue(readQueue, fail); npm.ResetQueues(); // kill the partially sent op (if any) if (currentWriteCopier != null) { currentWriteOp.Task.SetException(fail); currentWriteOp = OpQueueEntry.Empty; currentWriteCopier = null; } // kill the partially read response if (inprogressResponse != null) { inprogressResponse.Dispose(); inprogressResponse = null; } _FinishedReading(); _FinishedWriting(); // mark as dead if policy says so... if (failurePolicy.ShouldFail(this)) { IsAlive = false; return(true); } // ...otherwise reconnect immediately (when it's our turn) mustReconnect = true; LogTo.Info($"Node {endpoint} will reconnect immediately."); // reconnect from IO thread owner.NeedsIO(this); return(false); } }