Closed CptWesley closed 5 months ago
Are you sure about that? We definitely had this issue in local development, and I was consistently seeing the NpgsqlDataSource being disposed when IHost.Dispose() was called. Got a little more information to share about what you're doing?
On further inspection it appears we are creating our own NpgsqlDataSource
instance and passing that to marten to use. I'm not sure if that causes the issue. We are only using a single tenant.
I'm also not certain if marten should manage the lifetime of NpgsqlDataSource
instances that are passed to it, or whether or not they should be kept alive. Perhaps this could be determined by an optional boolean parameter, leaveOpen
, similarly to the parameter with same name of the StreamWriter
and StreamReader
constructors.
It appears that the NpgsqlDataSource is currently not being disposed when the ASP.NET Core application terminates gracefully, this means that the connections held by the pool might not be released. This mostly leads to database connection exhaustion in test projects that rapidly fire up many web applications and terminate them for each test case.
Current workaround: hook the
ApplicationStopping
lifetime event and dispose the data source manually.