diff --git a/hasql.cabal b/hasql.cabal
--- 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:
@@ -75,6 +75,7 @@
     StandaloneDeriving
     StrictData
     TupleSections
+    TypeApplications
     TypeFamilies
     TypeOperators
 
diff --git a/library/Hasql/Session/Core.hs b/library/Hasql/Session/Core.hs
--- a/library/Hasql/Session/Core.hs
+++ b/library/Hasql/Session/Core.hs
@@ -8,6 +8,7 @@
 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 @@
 -- 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,
