We have an Azure Function that is publishing messages to an Azure Event Hub via the built-in event hub integration binding that is then used to feed a Stream Analytics job. This has all been running fine then suddenly last night we started getting the following error in our Azure function that writes to the Event Hub:
Exception while executing function: Functions.LocationEventPublish. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Microsoft.ServiceBus: Cannot allocate more handles to the current session or connection. The maximum number of handles allowed is 4999. Please free up resources and try again.
Found the SO post below and understand why we are getting this and the suggested solution. However how are we supposed to only allocate a single instance of the client when using the built-in integration binding to publish from an Azure function to an event hub? Stopping and starting our Azure function resolved this issue but it seems this is a pretty major issue with using an Azure Function to populate an Event Hub.
Event Hub Exception Cannot Allocate More Handles To The Current Session or connection
The EventHub binding for Functions already does some caching of the clients (see https://github.com/Azure/azure-webjobs-sdk/blob/ffae7c86ea87fd73748186bac2c38c5401b80f68/src/Microsoft.Azure.WebJobs.ServiceBus/EventHubs/EventHubConfiguration.cs#L24 ) .
Can you share your function.json? Are you binding against many different event hubs?