简体   繁体   English

ASP.NET 核心 ILogger Memory Windows 10 (1607) / ZAEA2342289CE3AA9B340Z6 服务器泄漏

[英]ASP.NET Core ILogger Memory Leak on Windows 10 (1607) / Windows Server 2016

TL;DR TL;博士

I'm pretty sure now that there is a memory leak in the conhost process in Windows 10 (version 1607) and Windows Server 2016 that hasn't been there in Windows Server 2012 R2 and is fixed in Windows 10 (version 1809+) and Windows Server 2019. I'm pretty sure now that there is a memory leak in the conhost process in Windows 10 (version 1607) and Windows Server 2016 that hasn't been there in Windows Server 2012 R2 and is fixed in Windows 10 (version 1809+) and Windows 服务器 2019。

I couldn't find any official reference to that bug, if anyone can point that out for me I'd appreciate it.我找不到对该错误的任何官方参考,如果有人可以为我指出这一点,我将不胜感激。

Long story很长的故事

I'm currently investigating a memory-leak in our (self-hosted) ASP.NET Core Application that results in a high memory usage not of the.exe itself but of the corresponding 'conhost' process.我目前正在调查我们的(自托管)ASP.NET 核心应用程序中的内存泄漏,导致 memory 使用率很高,而不是.exe 本身,而是相应的“conhost”进程。 That will only happen on all production servers / VMs, running the same application my laptop (or any dev laptop) does not produce a memory leak.这只会发生在所有生产服务器/虚拟机上,运行相同的应用程序我的笔记本电脑(或任何开发笔记本电脑)不会产生 memory 泄漏。

Dev-Machine (running now for > 2h):开发机器(现在运行 > 2 小时): 在此处输入图像描述

Production Server (running for ~ 10min):生产服务器(运行约 10 分钟): 在此处输入图像描述

That memory will pile up indefinitely until the server runs out of memory.那个 memory 会无限堆积,直到服务器用完 memory。

That is the code I'm reproducing it with (again: on our production systems, not on dev machines).那是我用来复制它的代码(再次:在我们的生产系统上,而不是在开发机器上)。 In our real application it is actually EFCore logging causing the issue (EFCore also uses the ASP.NET Core Loggers):在我们的实际应用程序中,实际上是 EFCore 日志记录导致问题(EFCore 也使用 ASP.NET 核心记录器):

public class LoggingBackgroundService : BackgroundService
{
    private readonly ILogger<LoggingBackgroundService> logger;

    public LoggingBackgroundService(ILogger<LoggingBackgroundService> logger)
    {
        this.logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        for (var i = 0; i < 10; i++)
        {
            Task.Run(() => RunBackgroundThread(stoppingToken));
        }

        await Task.Delay(Timeout.Infinite, stoppingToken);
    }

    private async Task RunBackgroundThread(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            for (var i = 0; i < 1000; i++)
            {
                logger.LogInformation(GetLogMessage());
                //Console.WriteLine(GetLogMessage());
            }

            await Task.Delay(1000);
        }
    }

    private string GetLogMessage()
    {
        return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffff");
    }
}

Using Console.WriteLine() instead of the logger works and will not produce a memory leak.使用Console.WriteLine()代替记录器可以工作,并且不会产生 memory 泄漏。 And again one more time, that code works fine on a dev machine.再一次,该代码在开发机器上运行良好。

We are using .NET Core 3.1.我们使用的是 .NET Core 3.1。 Can anyone explain what's going on here?谁能解释这里发生了什么?

EDIT: My test-system currently sits at ~9 GB RAM, so maybe there is a limit but that's too much RAM spent on a 'conhost' process in any case.编辑:我的测试系统目前位于 ~9 GB RAM,所以也许有一个限制,但无论如何在“conhost”进程上花费的 RAM 太多了。 在此处输入图像描述

I also tried to use DebugDiag to analyze a memory dump, but that shows a stack trace that doesn't really help me (what else to expect though?):我还尝试使用 DebugDiag 来分析 memory 转储,但这显示了一个对我没有帮助的堆栈跟踪(还有什么可以期待的?):

LeakTrack+13277       
ConhostV2!MergeAttrStrings+b8       
ConhostV2!WriteCharsLegacy+a9c       
ConhostV2!DoSrvWriteConsole+4ea       
ConhostV2!ConsoleIoThread+36b       
kernel32!BaseThreadInitThunk+14       
ntdll!RtlUserThreadStart+21 

I only have a basic understanding of VMs but currently it looks like it is only happening in VMWare ESX (?) systems?我对虚拟机只有基本的了解,但目前看起来它只发生在 VMWare ESX (?) 系统中? I no longer think VMWare is causing the issue but was misled by the different Windows 10 Versions / Builds.我不再认为 VMWare 是导致问题的原因,而是被不同的 Windows 10 版本/构建所误导。

  • [Leak] Windows Server 2016 (on VMWare ESX) [泄漏] Windows 服务器 2016(在 VMWare ESX 上)
  • [Leak] Windows 10, 1607 (on VMWare ESX) [泄漏] Windows 10、1607(在 VMWare ESX 上)
  • [Leak] Windows 10, 1607 (on Azure) [泄漏] Windows 10、1607(在 Azure 上)
  • [Leak] Windows Server 2016 (on Azure) [泄漏] Windows 服务器 2016(在 Azure 上)
  • [Leak] Windows Server 2016 (on AWS) [泄漏] Windows 服务器 2016(在 AWS 上)
  • [Leak] Windows 10, 1607 (on Hyper-V) [泄漏] Windows 10、1607(在 Hyper-V 上)
  • [Leak] Windows Server 2016 (on Hyper-V) [泄漏] Windows 服务器 2016(在 Hyper-V 上)
  • [No Leak] Windows 10, 1909 (on VMWare Workstation) [无泄漏] Windows 10、1909(在 VMWare 工作站上)
  • [No Leak] Windows Server 2019 (on Azure) [无泄漏] Windows 服务器 2019(在 Azure 上)
  • [No Leak] Windows 10, 1909 (on Hyper-V) [无泄漏] Windows 10、1909(在 Hyper-V 上)
  • [No Leak] Windows Server 2019 (on Hyper-V) [无泄漏] Windows 服务器 2019(在 Hyper-V 上)
  • [No Leak] Windows 10, 1809 (on hardware) [无泄漏] Windows 10、1809(在硬件上)

I reported this bug to Microsoft and it has since been fixed.我向微软报告了这个错误,它已经被修复了。

... with the May 2021 Windows Server 2016 Update : ... 2021 年 5 月 Windows 服务器 2016 更新

A fix has been included in the May 2021 Windows Server 2016 update (KB5003197) but is hidden behind a feature flag. 2021 年 5 月 Windows 服务器 2016 更新 (KB5003197) 中包含一个修复程序,但隐藏在功能标志后面。 To activate it激活它

  1. Install KB5003197安装 KB5003197
  2. Add this registry entry: reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies\Microsoft\FeatureManagement\Overrides /v 1402424459 /t REG_DWORD /d 1 /f添加此注册表项: reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies\Microsoft\FeatureManagement\Overrides /v 1402424459 /t REG_DWORD /d 1 /f
  3. Restart the system重启系统

... with the June 2021 Windows Server Update: ... 2021 年 6 月 Windows 服务器更新:

This fix should be active with the June-Update without using the registry entry but I haven't tested this.在不使用注册表项的情况下,此修复程序应该在 June-Update 中处于活动状态,但我尚未对此进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法访问我在 windows 服务器 2016 中的 iis 下托管的 asp.net 核心服务器 - I cannot reach my asp.net core server hosted under iis in windows server 2016 Windows Server 2016 上的 IIS 10 未运行我的 ASP.NET MVC 网站 - IIS 10 on Windows Server 2016 not running my ASP.NET MVC website 通过 ASP.NET Core 2.2 在 Windows Server 2016 中不会触发 Headless Google Chrome - Headless Google Chrome Doesn't Fire in Windows Server 2016 via ASP.NET Core 2.2 如何将 ASP.NET 核心 web 应用程序部署到 ZAEA23489CE3AA9B6406EBB28E0CDA4016 上的 IIS 应用程序 - How to deploy ASP.NET core web application to IIS on Windows Server 2016 Windows 10上的.NET FontFamily内存泄漏 - .NET FontFamily memory leak on Windows 10 NET Core Windows服务中的内存泄漏问题 - Memory leak issue in windows services in .net core Asp.Net httpcontext.current.request在运行iis7的虚拟Windows Server 2012上有效,但在Windows Server 2016 iis10上无效 - Asp.Net httpcontext.current.request works on virtual windows server 2012 running iis7 but not on windows server 2016 iis10 ASP.NET Core 2+中的ILogger和DependencyInjection - ILogger and DependencyInjection in ASP.NET Core 2+ ASP.NET 内核中的 ILogger 和依赖注入架构 - ILogger and DependencyInjection Architecture in ASP.NET Core ASP.NET Core未连接到Windows Server 2012上的数据库 - ASP.NET Core not connecting to database on Windows Server 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM