[QueueTrigger] not deleting message if I extend the visibility timeout
See original GitHub issueI have a WebJob that can complete rapidly, or it can run for 30+ minutes. In the latter case, I use the v12 QueueClient.UpdateMessageAsync()
method to increase the visibility timeout on the message so that another instance doesn’t try to process the message again. The problem is that this also updates the QueueMessage
’s PopReceipt
. AFAICT, I have no way of updating the original QueueMessage
passed in by the queue processor, so when the processor tries to delete the message after the trigger method completes, the DELETE
fails with 404 The specified message does not exist.
Repro steps
- Add a method to the WebJob with a queue trigger:
public async Task ProcessQueueMessageAsync([QueueTrigger("my-queue")] QueueMessage message)
- Extend the message visibility timeout via
Azure.Storage.Queues.QueueClient.UpdateMessageAsync
:
// message is a QueueMessage
UpdateReceipt updateReceipt = await queueClient.UpdateMessageAsync(message.MessageId, message.PopReceipt, visibilityTimeout: TimeSpan.FromMinutes(10.0));
// New in Azure SDK v12: we have to update the message itself from the update receipt.
// This returns a new instance which contains a new PopReceipt and updated NextVisibleOn.
// Unfortunately, this does not get returned to the WebJobs framework because we're only
// updating a copy of the reference.
message = message.Update(updateReceipt);
Expected behavior
After the WebJob method runs successfully, I expect the queue message to be deleted.
Actual behavior
The DELETE call fails:
2021-12-02 03:43:54.947 [Information] [Azure.Core] Request [abb97a49-bd67-439e-bbb8-b7d9c85dd90e] DELETE https://myqueueservicename.queue.core.windows.net/my-queue/messages/342bf8d3-4449-4304-b58a-a545c2eb55c4?popreceipt=REDACTED
x-ms-version:REDACTED
Accept:REDACTED
x-ms-client-request-id:REDACTED
x-ms-return-client-request-id:REDACTED
User-Agent:REDACTED
x-ms-date:REDACTED
Authorization:REDACTED
client assembly: Azure.Storage.Queues
2021-12-02 03:43:55.055 [Warning] [Azure.Core] Error response [abb97a49-bd67-439e-bbb8-b7d9c85dd90e] 404 The specified message does not exist. (00.1s)
Server:REDACTED
x-ms-request-id:REDACTED
x-ms-version:REDACTED
x-ms-error-code:REDACTED
Date:REDACTED
Content-Length:REDACTED
Content-Type:REDACTED
The queue message remains in the queue, and is subsequently processed again.
Known workarounds
I don’t know of one. Is there a way to tell WebJobs about the new PopReceipt
?
Related information
- Package version: Microsoft.Azure.WebJobs.Host.Storage 4.0.4
- .NET SDK 6.0.100
- ASP.NET Core 6.0
- Visual Studio 2022
- Windows 10
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
@jonsagara It looks like it was added in this commit in extension version 3.0.32.
Yes, that is accurate. In case the extension is not able to update the message visibility, you should receive a log error with that information. But normally, yes, you should be able to run your function for an arbitrary amount of time without the message becoming visible again.
@hossam-nasr I didn’t know about the internal timer. Is that new in the storage-v4 version of the SDK?
If I understand correctly (restating in my own words), as long as the function continues to execute, and the process doesn’t crash, and the App Service remains available, the internal timer will update the message visibility periodically, allowing the function to run for an arbitrarily long amount of time. The message will remain invisible during for the duration of this execution time. Is that accurate?