Skip to content

Commit

Permalink
Ignore IOError on transaction rollback
Browse files Browse the repository at this point in the history
This should fix the timeout/withTransaction problem reported in #177
  • Loading branch information
lpsmith committed Jun 28, 2016
1 parent b40cd4f commit 71b4080
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Database/PostgreSQL/Simple/Transaction.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RecordWildCards, ScopedTypeVariables #-}

------------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -142,7 +142,7 @@ withTransactionMode :: TransactionMode -> Connection -> IO a -> IO a
withTransactionMode mode conn act =
mask $ \restore -> do
beginMode mode conn
r <- restore act `E.onException` rollback conn
r <- restore act `E.onException` rollback_ conn
commit conn
return r

Expand All @@ -167,7 +167,7 @@ withTransactionModeRetry mode shouldRetry conn act =
r <- act'
case r of
Left e -> do
rollback conn
rollback_ conn
case fmap shouldRetry (E.fromException e) of
Just True -> retryLoop act'
_ -> E.throwIO e
Expand All @@ -178,6 +178,10 @@ withTransactionModeRetry mode shouldRetry conn act =
rollback :: Connection -> IO ()
rollback conn = execute_ conn "ABORT" >> return ()

-- | Rollback a transaction, ignoring any @IOErrors@
rollback_ :: Connection -> IO ()
rollback_ conn = rollback conn `E.catch` \(_ :: IOError) -> return ()

-- | Commit a transaction.
commit :: Connection -> IO ()
commit conn = execute_ conn "COMMIT" >> return ()
Expand Down

0 comments on commit 71b4080

Please sign in to comment.