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

Fix spurious aborts when retrying transactions #34

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Database/PostgreSQL/Simple/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ 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
Expand All @@ -166,8 +166,7 @@ withTransactionModeRetry mode shouldRetry conn act =
beginMode mode conn
r <- act'
case r of
Left e -> do
rollback_ conn
Left e ->
3noch marked this conversation as resolved.
Show resolved Hide resolved
case fmap shouldRetry (E.fromException e) of
Just True -> retryLoop act'
_ -> E.throwIO e
Expand Down