Closed pabermod closed 6 months ago
Thank you for your feedback. Tagging and routing to the team member best able to assist.
My bad, the problem is that Task.Delay throws TaskCanceledException is the CancellationToken is cancelled. I thout it just ended the execution without throwing any exception
Anyway this is causing this strange exception, I think it should be revised
After doing more testing, with the following handler, if I stop the processor while executing the frist Task.Delay i'm still getting the exception:
private static ConcurrentDictionary<string, byte> receivingMessages = new ConcurrentDictionary<string, byte>();
async static Task MessageHandler(ProcessMessageEventArgs args)
{
string body = args.Message.Body.ToString();
Logger.Info($"[{args.Identifier}] SequenceNumber:{args.Message.SequenceNumber}, Lock Until:{args.Message.LockedUntil}, Received DateTime Utc: {DateTime.UtcNow}, DeliveryCount:{args.Message.DeliveryCount}");
Logger.Info($"[{args.Identifier}] Body is {body}");
if (receivingMessages.TryAdd(body, 0))
{
try
{
Logger.Info($"[{args.Identifier}] Doing first operation (90s)");
await Task.Delay(90000, args.CancellationToken).ConfigureAwait(false);
}
catch(TaskCanceledException)
{
await args.AbandonMessageAsync(args.Message).ConfigureAwait(false);
receivingMessages.TryRemove(body, out byte _);
return;
}
try
{
Logger.Info($"[{args.Identifier}] Doing second operation (3s)");
await Task.Delay(3000, args.CancellationToken).ConfigureAwait(false);
Logger.Info($"[{args.Identifier}] End message processing");
}
catch(TaskCanceledException ex)
{
Console.WriteLine($"ERROR: {ex.Message}");
}
finally
{
receivingMessages.TryRemove(body, out byte _);
await args.CompleteMessageAsync(args.Message);
Logger.Info($"[{args.Identifier}] Message completed");
}
}
}
I think the problem is when it tries to renew the lock and:
MaxAutoLockRenewalDuration = TimeSpan.MaxValue,
@pabermod, in order to have an infinite delay, you would need to set the property to Timeout.InfiniteTimeSpan.
Library name and version
Azure.Messaging.ServiceBus 7.17.1
Describe the bug
I have ServiceBusProcessor with the following handler:
If I stop the processor 5 seconds after start processing a message, The error handler is logging the following:
The stack trace of the exception is:
Expected behavior
There shouldn't be an error
Actual behavior
An ArgumentOutOfRangeException is generated and the ErrorHandler is executed
Reproduction Steps
Create a .Net project, Add the nuget, Create a client and use the code. After starting the processor add the following: await Task.Delay(5000); Console.WriteLine("Stop consumer"); await proc.StopProcessingAsync(); Console.ReadKey();
Create a topicwith subscription and send a message there. Start the application
Environment
No response