Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Hubs Functions stop triggering as the lease can't be renewed on an Storage Account v2 with Azure Data Lake Storage Gen 2 enabled.e Storage #81

Closed
FinVamp1 opened this issue Nov 27, 2020 · 4 comments
Assignees

Comments

@FinVamp1
Copy link
Member

FinVamp1 commented Nov 27, 2020

Issue Summary

Customers using the Azure Functions Event Hub Trigger may see that the Event Hub fails to trigger.
This happens when the Function App has AzureWebJobsStorage set to use a Storage v2 Account and Data Lake Storage Gen2 Hierarchical Namespace Enabled.

Issue Details

In addition if you check the Storage account you may notice that the leases have expired on the containers for the Consumer Group and Partition Id.

image

Or in Storage Explorer

image

The Azure Functions Event Hub Trigger uses the Event Processor Host library version 3.0.0. which uses v9 of the Storage SDK.

I think it might be related to the hierarchical namespace support that gets added from ADLS Gen 2. The leases are taken out on {EventHubNamespace}/{EventHubName}/{ConsumerGroupName}/{PartitionNumber} .

https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-supported-blob-storage-features

Issue Mitigation

There are currently two mitigations that will work longer term.

  1. The first approach is to have a Timer Trigger that checks if it can acquire the lease and then breaks it. This will ensure that the messages keep triggering the Function.
    It does not prevent the leases from being lost though. Sample code is attached.
  2. The customer can move to a Storage v2 account that does not have Data Lake Storage Gen 2 enabled. This is only configurable on creation of the storage account.

Sample Code
This code may need modifications as this is dependent on the number of partitions that the Event Hub supports.

`
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Blobs.Models;
using Azure;

namespace TestLeaseRenewal
{
public static class ExpiredLeaseFixer
{
[FunctionName("ExpiredLeaseFixer")]
public static async Task Run(
[TimerTrigger("0 */5 * * * * ")] TimerInfo myTimer,
ILogger log)
{
string connectionString = "{useStorageAccountConnStrHere";
string containerName = "azure-webjobs-eventhub";
string[] blobNames = {
"/{eventHubNameSpace}.servicebus.windows.net/{EventHubName}/{ConsumerGroupName}/0",
"/{eventHubNameSpace}.servicebus.windows.net/{EventHubName}/{ConsumerGroupName}/1",
"/{eventHubNameSpace}.servicebus.windows.net/{EventHubName}/{ConsumerGroupName}/2",
"/{eventHubNameSpace}.servicebus.windows.net/{EventHubName}/{ConsumerGroupName}/3",
"/{eventHubNameSpace}.servicebus.windows.net/{EventHubName}/{ConsumerGroupName}/4",
};

        BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
        BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

        foreach (string blobName in blobNames)
        {
            BlobClient blobClient = containerClient.GetBlobClient(blobName);
            BlobLeaseClient blobLeaseClient = new BlobLeaseClient(blobClient);
            try
            {
                BlobLease blobLease = await blobLeaseClient.AcquireAsync(TimeSpan.FromSeconds(15));
                blobLease = blobLeaseClient.Break();
                log.LogInformation("Lease for blob broken:" + blobName);
            }
            catch (Exception e)
            {
                log.LogInformation("Failed to break blob lease for:" + blobName);
            }
        }
    }
}

}
`

@sidkri
Copy link
Member

sidkri commented Dec 4, 2020

I can confirm that Event Hubs are aware of this limitation but the root cause is not known. For now, please use a storage account with Hierarchical namespace disabled. Please follow the best practice of using separate storage accounts for each Functions app and avoid using the same storage account used by your workflow as the account you configure in AzureWebJobsStorage or the EventHubs extension. The best practices are available here:
Functions best practices

@sidkri sidkri closed this as completed Dec 4, 2020
@ghost ghost removed the Needs: triage 🔍 label Dec 4, 2020
@AKUMARGA
Copy link

AKUMARGA commented Oct 6, 2021

While finding out the cause of the issue of event hub we come after scenario which we have done

Following scenario is working

  1. We created New Event Hub , Function app and storage account in same resource group.

  2. We created New Event Hub in other resource group and Function app and storage account in same resource group.

Following scenario is not working

  1. We created New Event Hub and Function app in same resource group and storage account in other resource group .

  2. We created New Event Hub in other resource group and Function app in other resource group and storage account in other resource group.

And after all this we know that function app and storage account should be in same group only then it will work.

So can you please tell us know that even we have found it is right or it will not work if there is a separate group of storage account and function app .

@cveld
Copy link

cveld commented Oct 14, 2021

No I don't think it is required to have the storage account in the same resource group as the function. Maybe there is something wrong with the connectionstring? Btw, your question is off-topic with regards to the original post.

@cveld
Copy link

cveld commented Oct 14, 2021

I was wondering if there is any error to be found in the logs when you use an HNS enabled storage account erroneously in combination with the event hub trigger binding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants