zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
467 stars 78 forks source link

[Host.Outbox.Sql] Exception causes outbox polling to fail in an in infinite loop (unable to resolve MessageType) #284

Closed EtherZa closed 1 month ago

EtherZa commented 2 months ago

When the MessageType fails to resolve, the OutboxSendingTask will fall into an infinite loop attempting to LockAndSelect the same messages, perpetually failing to publish/abort any of them.

This can occur when a message is added to the outbox but not published prior to the type registration being removed from the host application.

public async Task<IReadOnlyCollection<OutboxMessage>> LockAndSelect(string instanceId, int batchSize, bool tableLock, TimeSpan lockDuration, CancellationToken token)
{
        ...
        while (await reader.ReadAsync(token).ConfigureAwait(false))
        {
                ...
                BusName = reader.GetString(busNameOrdinal),
                MessageType = Settings.MessageTypeResolver.ToType(messageType) ?? throw new MessageBusException($"Outbox message with Id {id} - the MessageType {messageType} is not recognized. The type might have been renamed or moved namespaces."),
                MessagePayload = reader.GetSqlBinary(payloadOrdinal).Value,
                ...
        }
        ...
}
zarusz commented 1 month ago

I believe this was addressed in #285. Closing.