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

Automatically recovering from "connection disconnected" #85

Open
tchoutri opened this issue Apr 11, 2022 · 1 comment
Open

Automatically recovering from "connection disconnected" #85

tchoutri opened this issue Apr 11, 2022 · 1 comment

Comments

@tchoutri
Copy link

When inserting batches of data, I'm very often getting hit by

Exception: SqlError {sqlState = "", sqlExecStatus = FatalError,
  sqlErrorMsg = "connection disconnected", sqlErrorDetail = "", sqlErrorHint = ""}

This comes from how withConnection is defined:

-- | Atomically perform an action with the database handle, if there is one.
withConnection :: Connection -> (PQ.Connection -> IO a) -> IO a
withConnection Connection{..} m = do
    withMVar connectionHandle $ \conn -> do
        if PQ.isNullConnection conn
          then throwIO disconnectedError
          else m conn

I'd like to know if there are common ways to automatically reconnect upon such an exception.

Should I do something like use a try-catch at the db pool level?

@tchoutri
Copy link
Author

tchoutri commented Apr 11, 2022

@phadej do you know if there is some kind of hook I can use? I'm having a hard time determining the real cause of this but I could find some kind of workaround for the time being.

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

No branches or pull requests

1 participant