[英]How do I ensure our .NET Core APIs clean up database connections?
We are running .NET Core 1.1 APIs in Docker containers on Ubuntu 14.04. 我们在Ubuntu 14.04的Docker容器中运行.NET Core 1.1 API。 The API's interact with various SQL Server databases through EF Core, and what we are seeing is that databases connections are not being cleaned up, nor are they being reused.
该API通过EF Core与各种SQL Server数据库进行交互,我们看到的是数据库连接没有被清理,也没有被重用。 We are quickly seeing thousands of connections on the database through the sp_who2 query.
通过sp_who2查询,我们很快看到数据库上有数千个连接。
Scoped
lifecycle, so should be cleaned up after each session. Scoped
生命周期定义的,因此应在每次会话后清除。 Could this be by design in .NET Core? 可以是.NET Core中的设计吗? Or are we missing a trick?
还是我们错过了一个把戏? How could we force EF to do some connection cleanup?
我们如何强制EF进行一些连接清理?
We are now pretty sure that this is caused by a bug in the corefx System.Data.SqlClient which was fixed in version 4.3.1. 现在,我们非常确定这是由于corefx System.Data.SqlClient中的一个错误引起的,该错误已在4.3.1版中修复。 We were running 4.3.0 and have now updated to 4.3.1, and initial testing indicates that the problem is resolved.
我们正在运行4.3.0,现在已更新为4.3.1,初步测试表明问题已解决。
You can read more about the issue in the dotnet/corefx Github repository Issue #13422 . 您可以在dotnet / corefx Github存储库Issue#13422中阅读有关该问题的更多信息。
In summary, it appears to be a Linux-specific bug where the connections were not being disposed. 总而言之,这似乎是特定于Linux的错误,其中没有释放连接。
I will confirm/mark as the answer when we have proved this solves the problem to my satisfaction. 当我们证明这可以使我满意地解决问题时,我将确认/标记为答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.