简体   繁体   English

当托管在 linux 上时,ASP.NET 核心 IHostedService 停止

[英]ASP.NET Core IHostedService stops when hosted on linux

I have an ASP.NEt Core 3.1 application with Angular 8 frontend.我有一个带有 Angular 8 前端的 ASP.NET Core 3.1 应用程序。 It runs fine when hosted on IIS but as I have moved it onto a new Ubuntu 18 Server with Nginx above Kestrel sometimes the long running background processes stop working (IHostedService).它在托管在 IIS 上时运行良好,但是当我将它移到新的 Ubuntu 18 服务器上时,带有 Nginx 的 Kestrel 有时会停止长时间运行的后台进程。 Then the app runs towards accepting new requests so only the background process is stopped.然后应用程序运行以接受新请求,因此仅停止后台进程。

These processes get files from clients and give immediate responses with a process ids.这些进程从客户端获取文件并使用进程 ID 立即响应。 The clients can query the process state by their id.客户端可以通过id查询进程state。 Everything have been running fine for months now on IIS but the new config must have some limits that kills these processes.几个月来,IIS 上的一切都运行良好,但新配置必须有一些限制来杀死这些进程。 I suppose there is some kestrel or nginx option I don't know about and affect processes started by http requests.我想有一些红隼或 nginx 选项我不知道并影响由 http 请求启动的进程。

What options can I try and where can I get some logs?我可以尝试哪些选项,在哪里可以获得一些日志?

I've tried to log everything from .net core but even the most verbose logs are useless here.我尝试从 .net 核心记录所有内容,但即使是最冗长的日志在这里也没有用。 Nginx logs doesn't contain any info about the stopped process either. Nginx 日志也不包含有关已停止进程的任何信息。

Although the application runs fine hosted on IIS I tried to find catch blocks without any output and added logging into them but still nothing.尽管在 IIS 上托管的应用程序运行良好,但我试图找到没有任何 output 的 catch 块并添加登录到它们,但仍然没有。 Are there anything I can add to my application globals to log any exceptions handled or unhandled?有什么我可以添加到我的应用程序全局变量来记录任何已处理或未处理的异常吗?

I forgot to say that I use a local Microsoft SQL Server Express both on windows and linux.我忘了说我在 windows 和 linux 上都使用了本地 Microsoft SQL Server Express。 The linux Sql Server install was done by the official ms docs (as dotnet and nginx config, too). linux Sql 服务器安装由官方 ms 文档完成(也作为 dotnet 和 nginx 配置)。 The database is restored from a windows sql server backup.数据库从 windows sql 服务器备份恢复。 The connection string is the same with multipleresultsets=true.连接字符串与 multipleresultsets=true 相同。 Are there any differences I should aware of?有什么我应该注意的区别吗?

For anyone getting here in the future: this was caused by a bug in Microsoft.Data.SqlClient, so I had to update it (independently from EF Core 3.1.2) from nuget to the newer 1.1.2 version.对于将来来到这里的任何人:这是由 Microsoft.Data.SqlClient 中的错误引起的,所以我必须将它(独立于 EF Core 3.1.2)从 nuget 更新到更新的 1.1.2 版本。

When it stucked I had two threads waiting for each other, both in SqlClient.当它卡住时,我有两个线程在等待对方,都在 SqlClient 中。 With Just my code enabled VS debugger stopped at one of my linq queries.仅启用我的代码后,VS 调试器在我的 linq 查询之一处停止。 The only interesting part was that it never threw any exceptions and there was no deadlock event on the sql server either.唯一有趣的部分是它从未抛出任何异常,并且 sql 服务器上也没有死锁事件。 It just waited there so all logs were empty.它只是在那里等着,所以所有的日志都是空的。

https://github.com/dotnet/efcore/issues/18480 https://github.com/dotnet/efcore/issues/18480

https://github.com/dotnet/SqlClient/issues/262 https://github.com/dotnet/SqlClient/issues/262

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM