diff --git a/src/Wolverine/Envelope.Internals.cs b/src/Wolverine/Envelope.Internals.cs index 74b4bf6d3..585d916cb 100644 --- a/src/Wolverine/Envelope.Internals.cs +++ b/src/Wolverine/Envelope.Internals.cs @@ -240,7 +240,24 @@ internal async ValueTask QuickSendAsync() _enqueued = true; - if (Sender.Latched) return; + if (Sender.Latched) + { + // If the sender is latched, it indicates that the endpoint is currently unavailable + // (e.g., due to a network disconnection or a failure in the transport). + // In such cases, we should *not* attempt to send the message immediately. + // + // Instead, if the sender is a SendingAgent, we explicitly mark the envelope as failed + // so that it will be retried later when the connection is re-established. + // + // This conditional block ensures that latched agents skip enqueuing the message, + // but still track the failure to maintain durability and retry logic. + if (Sender is SendingAgent sendingAgent) + { + await sendingAgent.MarkProcessingFailureAsync(this, null); + } + + return; + } if (Sender.Endpoint?.TelemetryEnabled ?? false) {