Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NpgsqlDataSource not disposed on graceful termination #3175

Closed
CptWesley opened this issue May 2, 2024 · 2 comments · Fixed by #3176
Closed

NpgsqlDataSource not disposed on graceful termination #3175

CptWesley opened this issue May 2, 2024 · 2 comments · Fixed by #3176

Comments

@CptWesley
Copy link
Contributor

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.

@jeremydmiller
Copy link
Member

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?

jeremydmiller added a commit that referenced this issue May 2, 2024
…tions to try to guarantee the the NpgsqlDataSource's are all disposed. Closes GH-3175
@CptWesley
Copy link
Contributor Author

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.

jeremydmiller added a commit that referenced this issue May 2, 2024
…tions to try to guarantee the the NpgsqlDataSource's are all disposed. Closes GH-3175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants