public void HeartbeatReadTimerCallback(object state) { lock (_heartBeatReadLock) { if (m_hasDisposedHeartBeatReadTimer) { return; } bool shouldTerminate = false; try { if (!m_closed) { if (!m_heartbeatRead.WaitOne(0)) { m_missedHeartbeats++; } else { m_missedHeartbeats = 0; } // We check against 8 = 2 * 4 because we need to wait for at // least two complete heartbeat setting intervals before // complaining, and we've set the socket timeout to a quarter // of the heartbeat setting in setHeartbeat above. if (m_missedHeartbeats > 2 * 4) { string description = string.Format("Heartbeat missing with heartbeat == {0} seconds", m_heartbeat); var eose = new EndOfStreamException(description); ESLog.Error(description, eose); ShutdownReport.Add(new ShutdownReportEntry(description, eose)); HandleMainLoopException( new ShutdownEventArgs(ShutdownInitiator.Library, 0, "End of stream", eose)); shouldTerminate = true; } } if (shouldTerminate) { TerminateMainloop(); FinishClose(); } else if (_heartbeatReadTimer != null) { _heartbeatReadTimer.Change(Heartbeat * 1000, Timeout.Infinite); } } catch (ObjectDisposedException) { // timer is already disposed, // e.g. due to shutdown } catch (NullReferenceException) { // timer has already been disposed from a different thread after null check // this event should be rare } } }
public void LogCloseError(string error, Exception ex) { ESLog.Error(error, ex); ShutdownReport.Add(new ShutdownReportEntry(error, ex)); }