-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implications of running statements directly in IO #35
Comments
That's an interesting problem you're highlighting here. It raises questions in the direction of the Any way, if your session fails with QueryError but you restore from the error inside the session it will indeed cause the connection to stay in the pool. One thing to note here is that the latest release now spawns a maximal connection liftetime option. That one will at least cause all connections to get freed up after the period that you specify, so your pool won't stay poisoned forever. Still it's best to avoid handling QueryError within Session I guess. |
Somewhat unintuitively, it's not the MonadError instance that allows for bypassing the error handling, but the MonadReader instance. The "run" function converts a session to "Connection -> IO (Either QueryError a)", so inside the session passed to hasql-pool's "use" function, you only need a Connection (and liftIO) in order to end up with "Session (Either QueryError a)", which for "use" looks like a success, regardless of what the Either is. I'm not sure if there's a quick solution that fits within the current design, but since this only affects hasql-pool, and not plain hasql, I hope the MonadReader instance can remain, as it's very useful for interoperability with things like unliftio and effect systems. |
You're right. The Currently I see 2 ways to address the issue:
I think for now it would be best to go with the second option. |
Since "Session a" is isomorphic to "Connection -> IO (Either QueryError a)", it's relatively simple to integrate it with a custom application monad when using plain Hasql. With Hasql.Pool things get a bit more complicated, because the "use" function says it relies on the QueryError to determine if a connection is lost. What will happen if an application handles the QueryError in a different way, e.g. by logging it, and then "use" is only called when there's no QueryError (i.e. the return value of the IO action inside the Session passed to "use" is always "Right a")? Would a temporary connection problem then poison the pool and eventually make it impossible for the application to connect, or is that not an issue?
The text was updated successfully, but these errors were encountered: