rebus-org / Rebus.AzureServiceBus

:bus: Azure Service Bus transport for Rebus
https://mookid.dk/category/rebus
Other
33 stars 20 forks source link

Deadlettering fails due to deadLetterReason or deadLetterErrorDescription exceeding max #65

Closed Geminior closed 3 years ago

Geminior commented 3 years ago

When using the new UseNativeDeadlettering, the actual handler BuiltInDeadletteringErrorHandler will often fail due to exceeding the max length of the deadLetterReason or deadLetterErrorDescription imposed by MessageReceiver.OnDeadLetterAsync (4096)

Unhandled exception while handling message SampleChangedEvent/bf5cc4a3-775c-4bf9-adf7-bf5b64a90915
System.ArgumentOutOfRangeException: Maximum permitted length is 4096 (Parameter 'deadLetterErrorDescription')
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.OnDeadLetterAsync(String lockToken, IDictionary`2 propertiesToModify, String deadLetterReason, String deadLetterErrorDescription)
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.<>c__DisplayClass73_0.<DeadLetterAsync>b__0()
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.RetryPolicy.RunOperation(Func`1 operation, TimeSpan operationTimeout)
   at Microsoft.Azure.ServiceBus.Core.MessageReceiver.DeadLetterAsync(String lockToken, String deadLetterReason, String deadLetterErrorDescription)
   at Rebus.Config.AdditionalAzureServiceBusConfigurationExtensions.BuiltInDeadletteringErrorHandler.HandlePoisonMessage(TransportMessage transportMessage, ITransactionContext transactionContext, Exception exception)
   at Rebus.Retry.Simple.SimpleRetryStrategyStep.MoveMessageToErrorQueue(IncomingStepContext context, ITransactionContext transactionContext, Exception exception)
   at Rebus.Retry.Simple.SimpleRetryStrategyStep.Process(IncomingStepContext context, Func`1 next)
   at Rebus.ServiceProvider.ServiceProviderProviderStep.Process(IncomingStepContext context, Func`1 next)
   at Rebus.Workers.ThreadPoolBased.ThreadPoolWorker.ProcessMessage(TransactionContext context, TransportMessage transportMessage)

The message will actually end up in the dead letter queue, however not for the reason expected,

deadlettererrordescription
"Message could not be consumed after 100 delivery attempts."
deadletterreason
"MaxDeliveryCountExceeded"

which also means that it will disregard the retry count set in Rebus config and use whatever is set for the queue in Azure (as it occurs at this late stage).

The only real fix is to elipsis clamp the strings to the max length.

mookid8000 commented 3 years ago

Thanks for the detailed error description 🙂 it's fixed in Rebus.AzureServiceBus 8.1.1, which is on NuGet.org now!