DbContextPoolは ASP.NET Core 2.1で導入された新機能で、DbContextインスタンスの作成オーバーヘッドを節約しますが、その中に小さな穴が隠れています。 最近、ASP.NET Coreプロジェクトが一定期間連続稼働していたところ、ログにデータベース接続プールが最大接続数に達したというエラーが現れました。
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. at System.Data.Common.ADP.ExceptionWithStackTrace(Exception e)