Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

[BUG]Incorrect error: The session lock has expired on the MessageSession. Accept a new MessageSession. #19662

Closed qsdfplkj closed 3 years ago

qsdfplkj commented 3 years ago
[FunctionName("Run")]
public async Task Run([ServiceBusTrigger("queueName", Connection = "AzureWebJobsServiceBus", IsSessionsEnabled = true)] Message message, MessageReceiver messageReceiver)
{
        await messageReceiver.DeferAsync(message.SystemProperties.LockToken);
        message = await messageReceiver.ReceiveDeferredMessageAsync(message.SystemProperties.SequenceNumber);
        await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
}

in host json:

"extensions": {
    "serviceBus": {
      "messageHandlerOptions": {
        "autoComplete": false
      }
    }
  },

using func.exe writes this to the ouput

Message processing error (Action=Complete, ClientId=..., EntityPath=..., Endpoint=....servicebus.windows.net) Microsoft.Azure.ServiceBus: The session lock has expired on the MessageSession. Accept a new MessageSession.

Using microsoft.azure:

ghost commented 3 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @axisc.

Issue Details
[FunctionName("Run")] public async Task Run([ServiceBusTrigger("queueName", Connection = "AzureWebJobsServiceBus", IsSessionsEnabled = true)] Message message, MessageReceiver messageReceiver) { await messageReceiver.DeferAsync(message.SystemProperties.LockToken); message = await messageReceiver.ReceiveDeferredMessageAsync(message.SystemProperties.SequenceNumber); await messageReceiver.CompleteAsync(message.SystemProperties.LockToken); } in host json: "extensions": { "serviceBus": { "messageHandlerOptions": { "autoComplete": false } } }, using func.exe writes this to the ouput > Message processing error (Action=Complete, ClientId=QueueClient2dairy, EntityPath=dairy, Endpoint=d-adex-service-bus.servicebus.windows.net) > Microsoft.Azure.ServiceBus: The session lock has expired on the MessageSession. Accept a new MessageSession. > Using microsoft.azure: - microsoft.azure.functions.extensions 1.0.0 - microsoft.azure.webjobs.extensions.servicebus 4.1.1 - microsoft.azure.servicebus 4.1.2 - microsoft.azure.webjobs 3.0.25 - microsoft.azure.webjobs.extensions 3.0.6
Author: qsdfplkj
Assignees: -
Labels: `Client`, `Service Attention`, `Service Bus`, `customer-reported`, `needs-team-attention`, `needs-triage`, `question`
Milestone: -
qsdfplkj commented 3 years ago

The issue only seems to occur on queue that have sessions enabled.

axisc commented 3 years ago

@qsdfplkj This happens when the session lock is expired and needs to be reacquired.

If the issue persists after renewing the message lock, please consider opening a support ticket through the Azure Portal so that we can investigate the backend.

qsdfplkj commented 3 years ago

@axisc The issue is 100% reproducible with the repro I provided but we will be using sessionless queue. Why should I report it elsewhere? If you look at the stacktrace that is logged with the message you will notice that the underlying problem is that the code assumes it needs to complete it again.

axisc commented 3 years ago

but we will be using sessionless queue.

Not sure what you mean? can you elaborate?

If you look at the stacktrace that is logged with the message you will notice that the underlying problem is that the code assumes it needs to complete it again.

The issue here is that the lock is volatile and by the time your application attempts to complete the session, the lock is lost.

axisc commented 3 years ago

Closing this due to inactivity. Please feel free to reopen with details.

qsdfplkj commented 3 years ago

but we will be using sessionless queue.

Not sure what you mean? can you elaborate?

the issue only appears on session enabled queues but for me there is no priority on this anymore As we moved to sesionless and then this issue no longer reproduces. (But please what else did you think i was referring to? I more get the feeling that you are trying to avoid having to look into the issue than actually providing support)

If you look at the stacktrace that is logged with the message you will notice that the underlying problem is that the code assumes it needs to complete it again.

The issue here is that the lock is volatile and by the time your application attempts to complete the session, the lock is lost.

Look at the code “by the time” it’s 3 lines what time? It’s defer receive defer then complete. Why don’t you validate my repro?

chialiyun commented 3 years ago

Hi @qsdfplkj, I just faced this issue too and found out which part went wrong.

If we would like to enable session for the queue and would like to set autoComplete to false, we have to set it to sessionHandlerOptions instead of messageHandlerOptions

in host json:


"extensions": {
    "serviceBus": {
      "sessionHandlerOptions": {
        "autoComplete": false
      }
    }
  }

If you are still facing this issue, hope that helps!

Those are in reference to MS Docs in this link on the configurations for host.json for versions 2.x and higher:

If you have isSessionsEnabled set to true, the sessionHandlerOptions is honored. If you have isSessionsEnabled set to false, the messageHandlerOptions is honored.