I am using Azure Durable Function.
I found out that it hits the connections' limit:
I have been able to identify the call that is responsible for hitting the limit which is:
public class RecordStorage : IRecordStorage
{
private readonly CloudTableClient m_cloudTableClient;
public RecordStorage()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(/* Connection string */);
m_cloudTableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
m_cloudTableClient.DefaultRequestOptions.RetryPolicy = Constants.Storage.RetryPolicy;
}
public async Task UpsertAsync(string listId, ICollection<RecordBatch> recordBatches)
{
CloudTable cloudTable = m_cloudTableClient.GetTableReference(listId);
var tasks = new List<Task>();
foreach(var recordBatch in recordBatches)
{
var tableBatchOperation = new TableBatchOperation();
foreach(var batch in recordBatch.Records)
tableBatchOperation.Add(TableOperation.InsertOrReplace(new SomeTableEntity(***)));
/* THIS IS THE CALL THAT APPEAR TO BE CAUSING THE SPIKE OF CONNECTION */
tasks.Add(cloudTable.ExecuteBatchAsync(tableBatchOperation));
}
await Task.WhenAll(tasks);
}
}
This method is called indirectly within an activity.
I do not understand why it hits the limit since I made sure to reuse the CloudTableClient
instance. I also made sure the instance of RecordStorage
is injected in the other classes as a Singleton:
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddSingleton<IRecordStorage, RecordStorage>();
}
}
Question
Why am I exceeding the connection limit if I keep reusing the same CloudTableClient
instance?