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/