Azure / Azure/azure-functions-dotnet-worker
[BUG] "The session lock has expired on the MessageSession" when IsBatched = true
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
### Description
When using `ServiceBusTrigger` for a service bus queue with sessions enabled, the session lock is not being auto renewed when the `IsBatched` option is set to true. This causes a process that takes more than 1 minute to throw the expiration error.
Removing the IsBatched option allows the process to run up to the `maxAutoRenewDuration`. However, this removes the ability to process multiple messages as a batch.
### Steps to reproduce
1. Create a service bus queue with sessions enabled, then add a message to the queue
2. Create a new Azure Function (v4) project with Service Bus Queue trigger. Configure local.settings.json to include service bus connection details
3. Add `IsSessionsEnabled = true` to the `ServiceBusTrigger` attribute
4. Add a 65 second Task delay to the function to simulate a long running process
5. Run the application and wait for it to process the message. It should successfully process the message with no error.
6. Stop the application then add `IsBatched = true` to the `ServiceBusTrigger` attribute.
7. Add a new message to the service bus queue
8. Run the application once more. It should now throw an error at the end of the function after the delay has elapsed.
Below is the code from my `Function1.cs` file:
```
[Function("LockTestFunc")]
public async Task Run(
[ServiceBusTrigger("lock-test", Connection = "ServiceBusConnection", IsSessionsEnabled = true, IsBatched = true)]
ServiceBusReceivedMessage[] messages)
{
var start = DateTime.UtcNow;
_logger.LogInformation("{count} Messages Received: {start:yyyy-MM-dd HH:mm:ss}", messages.Length, start);
while (DateTime.UtcNow < start.AddSeconds(65))
{
await Task.Delay(5000);
var diff = DateTime.UtcNow - start;
_logger.LogInformation("Processing messages for: {min}min {sec}sec", diff.Minutes, diff.Seconds);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the issue with the Function1.cs trigger and local.settings.json configuration described in the report, comparing IsBatched = true and false. Trace the ServiceBusTrigger session-lock renewal path and verify that a 65-second batched session execution completes without an expiration error and still honors maxAutoRenewDuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100