ubuntu - Asp.Net Core - 已达到 inotify 实例数量的配置用户限制 (128)

标签 ubuntu asp.net-core entity-framework-core inotify

asp.net core MVC 在查询 mysql 数据库(在 Ubuntu 14.04/16.04 上)特定次数后报告错误,并显示以下消息: “已达到 inotify 实例数量的配置用户限制 (128)。” 可以确定是因为controller打开的文件太多,超过了iNotify设置的限制(在/proc/sys/fs/inotify/max_user_instances)引起的错误。但是当 ASP.NET 在每个 http 请求上打开文件时,我感到很困惑,为什么它没有正确关闭文件?有人也遇到过这个问题吗? 备注:我使用的是 Mysql.data.core 和 mysql.data.entityframeworkcore 提供者。

    private static string classiferstring = "sports,outdoor,startup,pets,child,adult,elderly";

    [AllowAnonymous]
    [HttpGet]
    public async Task<object> Classify([FromQuery] string classifyword)
    {
        string[] classifers = classiferstring.Split(',');
        if (!classifers.Contains(classifyword))
        {
            return new
            {
                status = 0,
                info = "WrongClassifier",
                Data = ""
            };
        }

        try
        {
            var predata = await (from d in _context.descriptor
                              join a in _context.combination on d.ID equals a.ID
                              select new ProductsVM
                              {
                                  CREATETIME = a.CREATETIME,
                                  ID = a.ID,
                                  COMPANY = a.COMPANY,
                                  NAME = a.NAME,
                                  PRICE = a.PRICE,
                                  TYPE = a.TYPE,
                                  HEADPHOTO = a.HEADPHOTO,
                                  REMARK = a.REMARK,

                                  Tags = d.Tags,
                                  Classifier = d.Classifier,
                                  OriginName = d.OriginName,
                                  Briefing = d.Briefing
                              }).ToListAsync();
            var data = (from x in predata
                          where x.Classifier.Contains(classifyword.ToLower())
                          select x).ToList();

            if(predata.Count<=0)
            {
                return new
                {
                    status = 2,
                    info = "NoResult",
                    Data = ""
                };
            }else
            {
                return new
                {
                    status = 1,
                    info = "Success",
                    Data = data
                };
            };
        }
        catch(Exception e)
        {
            return new
            {
                status = 0,
                info = "Error",
                Data = e.Message
            };
        }
    }

请注意异常仅在 try/catch 代码块中引发,而不是在调用操作后立即引发。

如果有人有解决此问题的线索,非常感谢。

最佳答案

到目前为止,我发现的最佳解决方案是通过运行以下命令增加 /etc/sysctl.conf 中的 fs.inotify.max_user_instances:

echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

来源:https://github.com/dotnet/aspnetcore/issues/8449#issuecomment-512275929

关于ubuntu - Asp.Net Core - 已达到 inotify 实例数量的配置用户限制 (128),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469400/

相关文章:

c - SQLException : Invalid column name 'CreateRequestViewModelRequestId'

entity-framework-core - 在 EFCore 中,我如何搭建我的上下文,然后开始进行迁移?

file - Ubuntu 如何使用终端将多个文本文件合并为一个

使用 apt-get 时命令行版本中缺少 PHP 模块

c# - EF Core HasData() 未在 OnModelCreating 内调用

c# - EF Core 2.1 - 如何映射具有相同类型的多对多

mongodb - ufw 只允许从我的 IP 地址(IPv6)访问 mongo

bash - 编写可以访问用户数据的 Cron 作业

asp.net-core - 在 Windows 中哪里可以找到 'dnu' 命令

json - 当我通过 AJAX 获取 JSON 数据时,数据存储在哪里?