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

Catch close() exceptions #2166

Merged
merged 1 commit into from Jun 15, 2021
Merged

Catch close() exceptions #2166

merged 1 commit into from Jun 15, 2021

Conversation

deusaquilus
Copy link
Collaborator

The call ZManaged.fromAutoCloseable does not catch exceptions thrown on connection.close() but instead directly proceeds to the die-channel. This makes sense for ZIO because resource-releases are typically indicative of filesystem-level resource leaks (e.g. open-file handles). However, for JDBC this does not make sense.

My Personal Thoughts about this issue:

Typically I think of finalizers as something you need to do in order to avoid OS-level resource leaks e.g. open-file handles, database connetions are a little different. They're a resource that can leak but when they do, the application should not have a panic-attack because ultimately the connection pool will "take care of it" and if it doesn't, the Database will. That's not to say that in high-system-stress production scenarios, Database resource leakage isn't dangerous, it most definitely is! However the way you typically deal with that is by putting circut breakers on the incoming user-connections and let 'enough time pass' so that the DB can kill off the connections that it can't serve. What you absolutely don't want to do is to kill the whole application since if you do, when it starts back up it will immediately hammer the DB with requests that have probably been buffered upstream.

It's interesting to note that in practice, nearly all of the cases where I've seen connection.close() fail is where a connection becomes stale (because it's held by a user-thread which is blocked by something else) and the database times out the connection. In practice, most good JDBC implementations try not to throw exceptions on a connecction.close() if another exception has already been thrown (especially if these connections are pooled!) but the JDBC API was designed to allow the former scenario to happen.

@getquill/maintainers

@deusaquilus deusaquilus merged commit f4d3979 into zio:master Jun 15, 2021
@deusaquilus deusaquilus deleted the catch_close branch June 15, 2021 14:34
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 this pull request may close these issues.

None yet

1 participant