Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Autocomplete = false ignored on Service Bus Binding (FunctionStartup related?)

Open Moffmo opened this issue 7 years ago • 8 comments

I have reproduced this issue with a very simple function

       [FunctionName("Function1")]
        public async Task Run(
            [ServiceBusTrigger("testqueue", Connection = "ServiceBusConnectionString")]Message message,
            MessageReceiver messageReceiver)
        {
            await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);


            await Task.Delay(70 * 1000);

            _logger.LogInformation($"C# ServiceBus queue trigger function processed message: {message.MessageId}");
        }

this is my host.json

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "messageHandlerOptions": {
        "autoComplete": false,
        "maxConcurrentCalls": 500
      }
    }
  }
}

I have a custom function startup.

[assembly: FunctionsStartup(typeof(Startup))]

namespace AutoCompleteIgnored
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            //Do nothing
        }
    }
}

Even though I have autoComplete: false in the host.json, it is still trying to renew the lock when the function has finished running - so it throws an exception for each function invocation

[23/07/2019 8:21:04 PM] MessageReceiver error (Action=RenewLock, ClientId=MessageReceiver1testqueue, EntityPath=testqueue, Endpoint=moffmo.servicebus.windows.net)[23/07/2019 8:21:04 PM] Microsoft.Azure.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. Reference:d8a0575d-d7b1-42f9-aaca-052bd6729015, TrackingId:0696ac9e-08f8-4a03-9645-8773d360c016_B8, SystemTracker:moffmo:Queue:testqueue, Timestamp:2019-07-23T20:21:05.

I have push the most basic reproduction of this issue to https://github.com/Moffmo/AzureFunctionServiceBusIssue feel free to clone to test.

Moffmo avatar Jul 23 '19 20:07 Moffmo

Even I am facing the same issue. Any fix or workaround for this?

reddaiahnethi avatar Jun 25 '20 06:06 reddaiahnethi

Same here! It was hard to google that, but finally found the same issue as mine.

If someone have anything, would be nice to share :)

wiliambuzatto avatar Aug 20 '20 00:08 wiliambuzatto

If you close the receiver, Its no longer trigger after lock time, but then it throws an error after function finishes.

await messageReceiver.CloseAsync();

-- no more error after lock time, but after function finished his execution it gets: (obvious because i close it) image

Why function keep trying to do something after we put "autoComplete": false, in host.json

wiliambuzatto avatar Aug 20 '20 00:08 wiliambuzatto

Also had this problem. It seems in this case it uses another setting for autoComplete.

"SessionHandlerOptions": {
        "autoComplete": false
      }

solved it for me.

rom-pystin avatar Aug 21 '20 11:08 rom-pystin

I am having the same issue - if I try to issue a Complete() method, I get an error when the process ends because it ignores any autoComplete: false directives, and tries to complete a message that has already been completed implicitly. I proved this by commenting-out my explicit Complete() call, but the message was still completed.

radsolution avatar Jan 27 '21 16:01 radsolution

Same issue here. It seems that the configuration autoComplete = false is not considered and the message is completed twice (once in the code await messageReceiver.CloseAsync() and the other time by the host) causing the exception "Message processing error (Action=Complete, ClientId=MessageReceiver...."

magazin81 avatar Mar 01 '21 21:03 magazin81

I had the same issue, it turns out this line is not needed: services.AddSingleton<IConfiguration>(root);

See details here https://github.com/Azure/azure-functions-servicebus-extension/issues/34

aleq avatar Mar 11 '21 10:03 aleq

For those of you still having this issue, e.g. host.json configs being overwritten by default values, and also having the need to load custom configs refer to this answer:

https://github.com/Azure/azure-functions-servicebus-extension/issues/34#issuecomment-596781972

A30006565 avatar Jul 18 '21 02:07 A30006565