Since you did not share any relevant piece of code from your function, my answer would be bit of generic. It seems to be due to socket exhaustion issue. While there is an inconclusive similar issue in github having some more details, a few good pointers to eliminate any low hanging fruits would be (I highly recommend you to read):
The major one I would particularly advise you to ensure shared connection reuse for Cosmos (or Table) client, HttpClient etc in a static private instance outside method.
Static clients
To avoid holding more connections than necessary, reuse client
instances rather than creating new ones with each function invocation.
We recommend reusing client connections for any language that you
might write your function in. For example, .NET clients like the
HttpClient,
DocumentClient,
and Azure Storage clients can manage connections if you use a single,
static client.
Here are some guidelines to follow when you're using a
service-specific client in an Azure Functions application:
- Do not create a new client with every function invocation.
- Do create a single, static client that every function invocation can use.
- Consider creating a single, static client in a shared helper class if different functions use the same service.
Example:
using Microsoft.Azure.Documents.Client;
private static Lazy<DocumentClient> lazyClient = new Lazy<DocumentClient>(InitializeDocumentClient);
private static DocumentClient documentClient => lazyClient.Value;
private static DocumentClient InitializeDocumentClient()
{
// Perform any initialization here
var uri = new Uri("example");
var authKey = "authKey";
return new DocumentClient(uri, authKey);
}
// Function
public static async Task Run(string input)
{
Uri collectionUri = UriFactory.CreateDocumentCollectionUri("database", "collection");
object document = new { Data = "example" };
await documentClient.UpsertDocumentAsync(collectionUri, document);
// Rest of function
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…