Cause of Service Bus 'cannot allocate more handles'

Adam 0 Reputation points
2025-07-07T23:15:48.6766667+00:00

We are occasionally encountering the Azure Service Bus 'Cannot allocate more handles' error, and I'm hoping to identify possible solutions. This is across a number of various Azure Function and Azure App Service apps that tend to use the same Service Bus resource, but act on different queues/subscriptions.

Frequently, others list making sure your ServiceBusClient is injected as a singleton, which I can confirm we are doing. However, will a failure to dispose of the objects such as ServiceBusSender also cause this issue? My online reading seems conflicted on this part. The docs (https://docs.azure.cn/en-us/service-bus-messaging/service-bus-performance-improvements?tabs=net-standard-sdk-2) say:

Closing or disposing the entity-specific objects (ServiceBusSender/Receiver/Processor) results in tearing down the link to the Service Bus service. Disposing the ServiceBusClient results in tearing down the connection to the Service Bus service.

It is unclear to me what is meant to be the difference between the two. Do the Sender/Receiver objects not create new connections?

Is it possible we just have too many apps using the same Service Bus resource and need to create different ones so not all connections go to the same resource?

Thank you!

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 13,330 Reputation points Volunteer Moderator
    2025-07-08T11:02:02.3766667+00:00

    hi Adam )) thanks for posting it here at Q&A.

    yes, not disposing senders and receivers can totally mess things up. even if u inject servicebusclient as a singleton, those sender and receiver objects still hog resources. the docs say closing them kills the link to service bus, while disposing the client nukes the whole connection. so they're different levels of cleanup )

    each sender/receiver creates its own link over the shared connection. too many links? boom, handle exhaustion. check if u're properly disposing them with 'using' blocks or manual dispose calls. this might help in other tools too where resource leaks creep in. as for the connection limits, service bus standard tier allows up to 5k concurrent connections per namespace. sounds like a lot, but with multiple apps sharing one namespace, it adds up fast. worth looking into splitting high traffic apps to separate namespaces if u're hitting limits. monitor 'active connections' metric in azure portal. if u see it climbing steadily, u've got leaks or just need more namespaces. its all in the docs here https://docs.microsoft.com/en-us/azure/service-bus-messaging/monitor-service-bus

    tune maxconcurrentcalls and prefetchcount on receivers. lower values mean fewer handles in use at once. sometimes slower is actually more stable )))

    service bus sdk automatically caches senders. so reusing the same sender instance is better than creating new ones constantly. less overhead, fewer handles. clever, right?

    if u're still stuck, maybe peek at connectionstatistics in servicebusclient to see where those handles are going :))

    hope this helps u

    best regards,

    Alex

    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    

    https://ctrlaltdel.blog/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.