microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
564 stars 287 forks source link

OutOfMemoryException due to referenced strings. #2910

Open yaroslavlsd opened 3 weeks ago

yaroslavlsd commented 3 weeks ago

Describe the bug

Azure Function application with an x86 environment (and ~2GB of process memory) crashed due to an OutOfMemoryException.

Analyzing the full memory dump shows that memory consists of too many strings (1.5GB) which are referenced by App Insights. We have some code, a simplified version is below, and we failed to properly set up the client configuration, resulting in a while loop without any delay. As a result, it looks like App Insights can't send logs, but new logs are incoming. A possible fix is to create a "MaxPendingLogsSize" option in the App Insights library and try to send only some of them.

I still have dump.

To Reproduce

while(true)
{
    logger.LogLnformation("Client started, now = {time}", DateTime.UtcNow);
    //await client.RunAsync();
}

Image