public async Task MonitorConnectionAsync() { await Task.Yield(); ChannelState state = ChannelState.Idle; while (state != ChannelState.Shutdown) { await Channel.WaitForStateChangedAsync(state); Logger.Log.GrpcTrace(m_loggingContext, $"[{Channel.Target}] Channel state: {state} -> {Channel.State}"); state = Channel.State; if (state == ChannelState.Idle) { // Try connecting with timeout (default 5min) // If it does not succeed, disconnect the worker. bool connectionSucceeded = await TryConnectChannelAsync(GrpcSettings.CallTimeout, nameof(MonitorConnectionAsync)); if (!connectionSucceeded) { OnConnectionTimeOutAsync?.Invoke(this, EventArgs.Empty); break; } } } }
public async Task MonitorConnectionAsync() { await Task.Yield(); ChannelState state = ChannelState.Idle; while (state != ChannelState.Shutdown) { await Channel.WaitForStateChangedAsync(state); Logger.Log.GrpcTrace(m_loggingContext, $"[{Channel.Target}] Channel state: {state} -> {Channel.State}"); state = Channel.State; if (state == ChannelState.Idle) { bool isReconnected = await TryReconnectAsync(); if (!isReconnected) { OnConnectionTimeOutAsync?.Invoke(this, EventArgs.Empty); break; } } } }
public async Task MonitorConnectionAsync() { await Task.Yield(); ChannelState state = ChannelState.Idle; while (state != ChannelState.Shutdown) { await Channel.WaitForStateChangedAsync(state); Logger.Log.GrpcTrace(m_loggingContext, $"[{Channel.Target}] Channel state: {state} -> {Channel.State}"); state = Channel.State; // If we requested 'exit' for the server, the channel can go to 'Idle' state. // We should not reconnect the channel again in that case. if (state == ChannelState.Idle && !m_isExitCalledForServer) { bool isReconnected = await TryReconnectAsync(); if (!isReconnected) { OnConnectionTimeOutAsync?.Invoke(this, EventArgs.Empty); break; } } } }
public async Task MonitorConnectionAsync() { await Task.Yield(); ChannelState state = ChannelState.Idle; while (state != ChannelState.Shutdown) { await Channel.WaitForStateChangedAsync(state); Logger.Log.GrpcTrace(m_loggingContext, $"[{Channel.Target}] Channel state: {state} -> {Channel.State}"); state = Channel.State; if (state == ChannelState.Idle) { // Try connecting with timeout (default 5min) // If it does not succeed, disconnect the worker. bool connectionSucceeded = await TryConnectChannelAsync(GrpcSettings.CallTimeout, nameof(MonitorConnectionAsync)); if (!connectionSucceeded && IsNonRecoverableState(Channel.State)) { // If re-connection attempt does not succeed; but the state is one of the recoverable states (Connecting, Ready, Transient) // Then, there is still a chance for the reconnection. OnConnectionTimeOutAsync?.Invoke(this, EventArgs.Empty); break; } } } }