Azure Service Bus message retry on TaskCancelationException

479 Views Asked by At

I'm using QueueClient message pump with AutoComplete option. When there is an exception thrown from the callback the message is retried and finally deadlettered.

Unfortunately when TaskCancelationException or OperationCanceledException is thrown from the callback this is not the case. The message gets autocompleted and never retried. Also OptionsOnExceptionReceived event handler is not called.

_queueClient = QueueClient.CreateFromConnectionString(connectionString, queueName, ReceiveMode.PeekLock);

...

public void OnMessageAsync(Func<BrokeredMessage, Task> callback)
    {
        if (_queueClient.IsClosed == false)
        {
            var options = new OnMessageOptions
            {
                MaxConcurrentCalls = _maxConcurrentCalls,
                AutoRenewTimeout = TimeSpan.FromMinutes(_autoRenewTimeoutInMinutes),
                AutoComplete = true
            };

            options.ExceptionReceived += OptionsOnExceptionReceived;

            _queueClient.OnMessageAsync(callback, options);
        }
    }

Am I doing something wrong here, is it a bug or maybe intended behaviour?

1

There are 1 best solutions below

0
On

I'm assuming. Don't know what the actual code is doing (this client is not opened source and in the new client looks like this situation should not happen). There's exception handling around your callback that ASB client is performing, but it fails to handle task exceptions, allowing completion of the message. You can raise an issue with the ASB team for the client here.