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.

[QUERY] ServiceBus QuotaExceeded when creating Session Receiver

See original GitHub issue

Library name and version

Azure.Messaging.ServiceBus 7.4.0

Query/Question

We seem to have started hitting a limit with a Quota on the number of handlers that are getting spun up for AMPQ connections as shown by the stack below

Azure.Messaging.ServiceBus.ServiceBusException: Cannot allocate more handles. The maximum number of handles is 4999. (QuotaExceeded)
   at Azure.Messaging.ServiceBus.Amqp.AmqpConnectionScope.CreateReceivingLinkAsync(String entityPath, String identifier, AmqpConnection connection, Uri endpoint, TimeSpan timeout, UInt32 prefetchCount, ServiceBusReceiveMode receiveMode, String sessionId, Boolean isSessionReceiver, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.Amqp.AmqpConnectionScope.OpenReceiverLinkAsync(String identifier, String entityPath, TimeSpan timeout, UInt32 prefetchCount, ServiceBusReceiveMode receiveMode, String sessionId, Boolean isSessionReceiver, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.OpenReceiverLinkAsync(TimeSpan timeout, UInt32 prefetchCount, ServiceBusReceiveMode receiveMode, Boolean isSessionReceiver, String identifier)
   at Microsoft.Azure.Amqp.FaultTolerantAmqpObject`1.OnCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Microsoft.Azure.Amqp.Singleton`1.GetOrCreateAsync(TimeSpan timeout)
   at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<>c__DisplayClass68_0.<<OpenLinkAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation(Func`2 operation, TransportConnectionScope scope, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation(Func`2 operation, TransportConnectionScope scope, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.OpenLinkAsync(CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.ServiceBusReceiver.OpenLinkAsync(CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.ServiceBusSessionReceiver.CreateSessionReceiverAsync(String entityPath, ServiceBusConnection connection, IList`1 plugins, ServiceBusSessionReceiverOptions options, String sessionId, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.ServiceBusClient.AcceptSessionAsync(String queueName, String sessionId, ServiceBusSessionReceiverOptions options, CancellationToken cancellationToken)

We use one ServiceBusClient for all of the session receivers we have running and we may have started running more than 5000 session receivers concurrently as when we decreased the amount of receivers we were running this error resolved. I’m trying to understand why this might occur because I was under the impression that one client reuses the same ampq connection for any amount of receivers.

I can’t find a whole lot of information on what exactly this error indicates but it seems like its happening on creating a AMPQ receiving link. Can someone help me understand what might be the issue here? Does this indicate that we are hitting the 5000 concurrent connections on a namespace? In telemetry it shows only 1 active connection to the namespace. I’m just trying to understand why this started happening so I can figure out steps to resolve.

Environment

.Net 5

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
royramstacommented, Dec 16, 2021

I took ownership of the support request, I will update here when Service Bus product team shares their response.

1reaction
chris-skuvaultcommented, Dec 27, 2021

This has been answered by support so want to follow up with information that was learned. Each ServiceBusClient creates an AMPQ connection. The AMPQ connection has limitations on the number of links that can be opened. The limit seems to be 4999. Documentation is going to be updated to help provide more information about this as it doesn’t currently seem to be documented.

The receiver itself takes up 2 links, one for service bus sending a message to it and one for the receiver replying to service bus with a response to renew, complete, abandon, etc. Which is why when we got close to 2.5k receivers running we started to hit the quota of 4999 AMPQ links.

The solution that was recommended was to increase the number of AMPQ connections being used and distribute the load across more AMPQ connections. We decided to create a separate connection for each sender and a separate connection per 100 sessions that were running. Since we have 9 queues associated with each session then a single AMPQ connection will get 900 receivers running on it which should allow us plenty of room to not hit that AMPQ link quota. In testing when switching to this implementation we haven’t seen any link quota issues like before.

This documentation https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-protocol-guide#create-message-receiver was helpful to understand how the AMPQ links worked to understand the issue we were running into with the link quota.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Service Bus Exception : Cannot allocate more ...
(QuotaExceeded)) essentially means the client is creating unbounded number of senders or receivers on the same connection. Each MessagingFactory ...
Read more >
[BUG] Azure.Messaging.ServiceBus Session processor ...
It may be locked by another receiver" and then after these I get "Cannot allocate more handles. The maximum number of handles is...
Read more >
Suggestions for Implementing Session Block for Service Bus
Say I have a few messages deferred for userId/sessionId: A . And when I want to unblock the processing for this user I...
Read more >
Class: Azure::ServiceBus::ServiceBusService
Specifies the time span during which the Service Bus will detect message ... If set to true, the queue will be session-aware and...
Read more >
Azure Service Bus Session Enabled Message Processing
The session enabled Azure Service Bus Queue can be created by setting the 'RequireSession' property to true, using WindowsAzure.
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