From 52cfda4e91ea484d22cb038d09e5d2882d692323 Mon Sep 17 00:00:00 2001 From: Nikita Volkov Date: Fri, 13 Sep 2024 07:40:00 +0300 Subject: [PATCH 1/2] Add connection reset on exceptions in non-idle transaction status --- hasql.cabal | 1 + library/Hasql/Session/Core.hs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hasql.cabal b/hasql.cabal index eb3a2f2..7e9bedf 100644 --- a/hasql.cabal +++ b/hasql.cabal @@ -75,6 +75,7 @@ common base StandaloneDeriving StrictData TupleSections + TypeApplications TypeFamilies TypeOperators diff --git a/library/Hasql/Session/Core.hs b/library/Hasql/Session/Core.hs index 0e5d139..d02900d 100644 --- a/library/Hasql/Session/Core.hs +++ b/library/Hasql/Session/Core.hs @@ -8,6 +8,7 @@ import Hasql.Encoders.All qualified as Encoders import Hasql.Encoders.Params qualified as Encoders.Params import Hasql.Errors import Hasql.IO qualified as IO +import Hasql.LibPq14 qualified as Pq import Hasql.Pipeline.Core qualified as Pipeline import Hasql.Prelude import Hasql.Statement qualified as Statement @@ -22,8 +23,20 @@ newtype Session a -- Executes a bunch of commands on the provided connection. run :: Session a -> Connection.Connection -> IO (Either SessionError a) run (Session impl) connection = - runExceptT + handle @SomeException onExc + $ runExceptT $ runReaderT impl connection + where + onExc exc = + case connection of + Connection.Connection pqConnVar _ _ -> + withMVar pqConnVar onPqConn + where + onPqConn pqConn = do + Pq.transactionStatus pqConn >>= \case + Pq.TransIdle -> pure () + _ -> Pq.reset pqConn + throwIO exc -- | -- Possibly a multi-statement query, From 34c540df5fca3e477dc1bee27751cb3c523527e7 Mon Sep 17 00:00:00 2001 From: nikita-volkov Date: Fri, 13 Sep 2024 04:58:02 +0000 Subject: [PATCH 2/2] Set package version to 1.8.1 --- hasql.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasql.cabal b/hasql.cabal index 7e9bedf..8b2ce78 100644 --- a/hasql.cabal +++ b/hasql.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: hasql -version: 1.8.0.2 +version: 1.8.1 category: Hasql, Database, PostgreSQL synopsis: Fast PostgreSQL driver with a flexible mapping API description: