diff --git a/src/Transports/RabbitMQ/Wolverine.RabbitMQ/Internal/RabbitMqChannelAgent.cs b/src/Transports/RabbitMQ/Wolverine.RabbitMQ/Internal/RabbitMqChannelAgent.cs index cc4e94bbc..087d5466e 100644 --- a/src/Transports/RabbitMQ/Wolverine.RabbitMQ/Internal/RabbitMqChannelAgent.cs +++ b/src/Transports/RabbitMQ/Wolverine.RabbitMQ/Internal/RabbitMqChannelAgent.cs @@ -119,7 +119,6 @@ private Task HandleChannelExceptionAsync(object? sender, CallbackExceptionEventA await Locker.WaitAsync(); try { - _monitor.Remove(this); try { await teardownChannel(); @@ -137,6 +136,18 @@ private Task HandleChannelExceptionAsync(object? sender, CallbackExceptionEventA Logger.LogInformation("Restarted the Rabbit MQ channel"); } + catch (Exception e) + { + // The broker is likely unavailable (e.g. a broker roll). Leave this agent registered + // with the ConnectionMonitor and marked Disconnected so RecoverySucceededAsync rebuilds + // it once the connection returns. Previously the agent was removed from the monitor + // before the restart attempt, so a failure here orphaned it permanently: the connection + // recovery loop iterates the monitor's tracked agents, so a removed listener is never + // rebuilt and its queue is left with zero consumers on an otherwise-healthy process. + State = AgentState.Disconnected; + Logger.LogWarning(e, + "Could not eagerly restart the Rabbit MQ channel; leaving it for connection recovery"); + } finally { Locker.Release();