git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix spurious aborts when retrying transactions
61837ebElliot Cameron
src/Database/PostgreSQL/Simple/Transaction.hs+2−3
@@ -157,7 +157,7 @@ withTransactionModeRetry :: TransactionMode -> (SqlError -> Bool) -> Connection
157withTransactionModeRetry mode shouldRetry conn act =
157withTransactionModeRetry mode shouldRetry conn act =
158 mask $ \restore ->
158 mask $ \restore ->
159 retryLoop $ E.try $ do
159 retryLoop $ E.try $ do
160− a <- restore act
160+ a <- restore act `E.onException` rollback_ conn
161 commit conn
161 commit conn
162 return a
162 return a
163 where
163 where
@@ -166,8 +166,7 @@ withTransactionModeRetry mode shouldRetry conn act =
166 beginMode mode conn
166 beginMode mode conn
167 r <- act'
167 r <- act'
168 case r of
168 case r of
169− Left e -> do
169+ Left e ->
170− rollback_ conn
171 case fmap shouldRetry (E.fromException e) of
170 case fmap shouldRetry (E.fromException e) of
172 Just True -> retryLoop act'
171 Just True -> retryLoop act'
173 _ -> E.throwIO e
172 _ -> E.throwIO e