I'm not saying it was built with Azure Functions, but it was definitely built with Azure Functions.

How to fix “The listener for function was unable to start. Out of retries creating lease for partition 0”

This post was most recently updated on July 27th, 2022.

2 min read.

Here is another pretty quick one – trying to debug Azure Functions fails with a confusing error message about failing to create a lease for a partition. But as usual, the fix is (probably) simple, and this article explains what to do :)

So, hey future me, finding this article on Google! 🙋‍♂️

Let’s get to it, then!


Table of Contents

When trying to debug your Azure Function, you get an error somewhat like this:

The listener for function [function name] was unable to start. Microsoft.Azure.EventHubs.Processor: Out of retries creating lease for partition 0. Microsoft.WindowsAzure.Storage: The response ended prematurely, with at least 171 additional bytes expected. System.Net.Http: The response ended prematurely, with at least 171 additional bytes expected.

And that’s it. No Azure Functions for you!

What do?


Your consumer group is probably wrong – start the investigation by changing it!

I’ve actually already explained how to do that here, but here’s a refresher:

Time needed: 30 minutes.

How to fix “Microsoft.WindowsAzure.Storage: Server encountered an internal error.”?

  1. Create a new Consumer Group for your IoT Hub

    Navigate to Azure IoT Hub, and “Built-in Endpoints” underneath it. On that blade/tab, you should see something like below – create a new consumer group by entering a new alphanumeric value (hyphens supported) in the field and saving the changes.

  2. Add a new application setting for your Consumer Group

    Now you’ll need to tell your Azure Function the name of the consumer group you want it to use.

    Something like this:
    "Values": {
    "AzureIoTHubConsumerGroupName": "MyCustomConsumerGroup"

  3. Add the “ConsumerGroup” parameter to your trigger (if it doesn’t exist already)

    In code, this will look somewhat like the below:

    public static Task Run(
    Connection = "EventHubConnectionAppSetting",
    ConsumerGroup = "%AzureIoTHubConsumerGroupName%"
    )] EventData myEventHubMessage)

  4. Restart debugging/redeploy

    And you should be good.

And that should be it! Unless it isn’t. In that case, feel free to let me know in the comments section below, and let’s investigate together!


5 2 votes
Article Rating
Notify of

Inline Feedbacks
View all comments