Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Database/PostgreSQL/Simple/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,19 @@ withTransactionModeRetry :: TransactionMode -> (SqlError -> Bool) -> Connection
withTransactionModeRetry mode shouldRetry conn act =
mask $ \restore ->
retryLoop $ E.try $ do
a <- restore act
a <- restore act `E.onException` rollback_ conn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, rollback_ is not exported and it's also suspicious. It catches exceptions thrown when issuing the rollback. Why is that a good idea?

commit conn
return a
where
retryLoop :: IO (Either E.SomeException a) -> IO a
retryLoop :: IO (Either SqlError a) -> IO a
retryLoop act' = do
beginMode mode conn
r <- act'
case r of
Left e -> do
rollback_ conn
case fmap shouldRetry (E.fromException e) of
Just True -> retryLoop act'
_ -> E.throwIO e
Left e ->
case shouldRetry e of
True -> retryLoop act'
False -> E.throwIO e
Right a ->
return a

Expand Down