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.

[BUG] Microsoft.Azure.WebJobs.Extensions.ServiceBus delay between batches of session-based messages

See original GitHub issue

Library name and version

Microsoft.Azure.WebJobs.Extensions.ServiceBus, 5.3.0

Describe the bug

Didn’t realize v5.x moved here, see info from this other issue in the old repo. https://github.com/Azure/azure-functions-servicebus-extension/issues/180#issue-1163179060

TLDR: A simple ServiceBusTrigger is seeing a delay after processing MaxConcurrentSessions messages that appears related to the TryTimeout setting.

Expected behavior

To keep processing messages until there are no more messages in the queue.

Actual behavior

Process 8 messages, delay of 1 minute, process 8 messages, repeat until queue is empty.

This is actually causing the Azure scaler to scale-out the function app to max nodes as the queue does not get emptied fast enough.

Reproduction Steps

Function:

using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.ServiceBus;
using Microsoft.Extensions.Options;

namespace FunctionApp1
{
    public class Function1
    {
        [FunctionName("Function1")]
        public async Task RunAsync([ServiceBusTrigger("queue-name", IsSessionsEnabled = true)] string json)
        {
        }
    }
}

host.json

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "Debug"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsServiceBus": "Endpoint=sb://.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

Environment

This happens locally and appears to be happening when deployed in Azure. Also noticed similar behavior on dotnet-isolated worker with similar code/setup except that it would process 2000 messages and then wait because the MaxConcurrentSessions value is 2000 instead of 8 as it was in the in-process worker.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vipinlalvscommented, Apr 5, 2022

@smokedlinq, did you get any workaround/fix on this?. We are also facing similar issue.

0reactions
smokedlinqcommented, Apr 5, 2022

Yes I lowered the SessionIdleTimeout setting to 1 second. The session will wait for more messages before giving up. The default is 1 minute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for improving performance using Azure ...
To increase the throughput of a queue, topic, or subscription, Service Bus batches multiple messages when it writes to its internal store. When ......
Read more >
ServiceBusOptions Class (Microsoft.Azure.WebJobs. ...
If less than MinMessageBatchSize messages were available before the wait time elapses, the function will be invoked with a partial batch. This value...
Read more >
Azure Service Bus bindings for Azure Functions
This version allows you to bind to types from Azure.Messaging.ServiceBus. This extension version is available by installing the NuGet package, ...
Read more >
dotnet-isolated ServiceBusTrigger very slow with ...
I am seeing very slow ServiceBusTrigger trigger behavior for queues that are session enabled. It looks like a 'batch' amount of messages are ......
Read more >
Azure Function triggered by Service Bus Queue event ...
Today, I pushed 84 messages on the queue in 5 minutes. These messages were scheduled to run over a 1 hour period also...
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