0

I'm developing an Azure Service Bus trigger function with MassTransit, and I'm getting the following error messages when the bus is injected with about 10K messages in a short time (~5 mins).

The function should read the messages coming from the bus, do a transformation, and then queue a subsequent message into another topic.

Here's the error message I'm getting:

Cannot allocate more handles. The maximum number of handles is 4999. (QuotaExceeded). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.

Exception type: Azure.Messaging.ServiceBus.ServiceBusException

Failed method: Azure.Messaging.ServiceBus.Amqp.AmqpConnectionScope+<CreateSendingLinkAsync>d__85.MoveNext

Here's my Function App Code:

[FunctionName(nameof(HubspotWebhookCommandReceiver))]
    public async Task Run([ServiceBusTrigger("%HubspotWebhook:CommandQueueName%", Connection = "ServiceBusConnection")]
    ServiceBusReceivedMessage[] messages, CancellationToken cancellationToken)
    {
        _logger.LogInformation("Handling {count} Hubspot Webhook Commands", messages.Count());

        var handles = new List<Task>();

        foreach (var message in messages)
        {           
            handles.Add(_messageReceiver.HandleConsumer<HubspotWebhookCommandConsumer>(_configuration.CommandQueueName, message, cancellationToken));
        }

        await Task.WhenAll(handles);
    }

And the host.json file:

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensions": {
    "http": {
      "routePrefix": ""
    },
    "serviceBus": {
      "prefetchCount": 100,
      "messageHandlerOptions": {
        "autoComplete": true,
        "maxConcurrentCalls": 16,
        "maxAutoRenewDuration": "00:05:00"
      },
      "batchOptions": {
        "maxMessageCount": 1000,
        "operationTimeout": "00:01:00",
      }
    }
  }
}

Any suggestions would be much appreciated, as I've been trying to fix the issue for a couple of days now. Thanks!

1
  • Try to reduce the prefetchCount and maxConcurrentCalls in your host.json to reduce the number of concurrent connections and avoid exceeding the handle limit. Commented May 6 at 5:58

1 Answer 1

0

Finally I got to the solution, the root cause of the issue was that message consumers had a reference for } ServiceBusSender (from Microsoft's framework) and we were not disposing those instances which led into the allocation problem. I was able to fix it by adding a using statement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.