question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QueueTrigger] not deleting message if I extend the visibility timeout

See original GitHub issue

I 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

  1. Add a method to the WebJob with a queue trigger:
public async Task ProcessQueueMessageAsync([QueueTrigger("my-queue")] QueueMessage message)
  1. 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:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hossam-nasrcommented, Jan 31, 2022

@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.

1reaction
jonsagaracommented, Jan 31, 2022

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

QueueTrigger Attribute Visibility Timeout - azure
Quoting the Azure Website: "When the method completes, the queue message is deleted. If the method fails before completing, the queue message is ......
Read more >
Have the ability to programatically -not- delete a message if ...
I asked on SO how to control the deleting and invisibility of a message and got some mixed results. This SDK has the...
Read more >
Azure Queue storage trigger for Azure Functions
Use the queue trigger to start a function when a new item is received on a queue. The queue message is provided as...
Read more >
Configuring a queue to trigger an AWS Lambda function ...
Learn how to configure messages arriving in an Amazon SQS queue to trigger an AWS Lambda function.
Read more >
Working with AWS CLI SQS: Simplified 101 - Learn
If you don't delete a message after it's been received, the message's visibility timeout reverts to the original value (rather than the value ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found