Skip to content

Commit 6f98332

Browse files
chore(deps): update hasql to 1.8.1.4
1 parent abb04f4 commit 6f98332

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

nix/overlays/haskell-packages.nix

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ let
4949
# Before upgrading fuzzyset to 0.3, check: https://github.com/PostgREST/postgrest/issues/3329
5050
# jailbreak, because hspec limit for tests
5151
fuzzyset = prev.fuzzyset_0_2_4;
52-
53-
# Downgrade hasql and related packages while we are still on GHC 9.4 for the static build.
54-
hasql = lib.dontCheck (lib.doJailbreak prev.hasql_1_6_4_4);
55-
hasql-dynamic-statements = lib.dontCheck prev.hasql-dynamic-statements_0_3_1_5;
56-
hasql-implicits = lib.dontCheck prev.hasql-implicits_0_1_1_3;
57-
hasql-notifications = lib.dontCheck prev.hasql-notifications_0_2_2_2;
58-
hasql-pool = lib.dontCheck prev.hasql-pool_1_0_1;
59-
hasql-transaction = lib.dontCheck prev.hasql-transaction_1_1_0_1;
60-
postgresql-binary = lib.dontCheck (lib.doJailbreak prev.postgresql-binary_0_13_1_3);
6152
};
6253
in
6354
{

postgrest.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ library
107107
, either >= 4.4.1 && < 5.1
108108
, extra >= 1.7.0 && < 2.0
109109
, fuzzyset >= 0.2.4 && < 0.3
110-
, hasql >= 1.6.1.1 && < 1.7
110+
, hasql >= 1.7 && < 1.9
111111
, hasql-dynamic-statements >= 0.3.1 && < 0.4
112-
, hasql-notifications >= 0.2.2.2 && < 0.2.3
113-
, hasql-pool >= 1.0.1 && < 1.1
112+
, hasql-notifications >= 0.2.2.0 && < 0.3
113+
, hasql-pool >= 1.1 && < 1.3
114114
, hasql-transaction >= 1.0.1 && < 1.2
115115
, heredoc >= 0.2 && < 0.3
116116
, http-types >= 0.12.2 && < 0.13

src/PostgREST/AppState.hs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,30 @@ initPool AppConfig{..} observer = do
215215
-- | Run an action with a database connection.
216216
usePool :: AppState -> SQL.Session a -> IO (Either SQL.UsageError a)
217217
usePool AppState{stateObserver=observer, stateMainThreadId=mainThreadId, ..} sess = do
218-
observer PoolRequest
218+
observer PoolRequest
219219

220-
res <- SQL.use statePool sess
220+
res <- SQL.use statePool sess
221221

222-
observer PoolRequestFullfilled
222+
observer PoolRequestFullfilled
223223

224-
whenLeft res (\case
225-
SQL.AcquisitionTimeoutUsageError ->
226-
observer $ PoolAcqTimeoutObs SQL.AcquisitionTimeoutUsageError
227-
err@(SQL.ConnectionUsageError e) ->
228-
let failureMessage = BS.unpack $ fromMaybe mempty e in
229-
when (("FATAL: password authentication failed" `isInfixOf` failureMessage) || ("no password supplied" `isInfixOf` failureMessage)) $ do
230-
observer $ ExitDBFatalError ServerAuthError err
231-
killThread mainThreadId
232-
err@(SQL.SessionUsageError (SQL.QueryError tpl _ (SQL.ResultError resultErr))) -> do
224+
whenLeft res (\case
225+
SQL.AcquisitionTimeoutUsageError ->
226+
observer $ PoolAcqTimeoutObs SQL.AcquisitionTimeoutUsageError
227+
err@(SQL.ConnectionUsageError e) ->
228+
let failureMessage = BS.unpack $ fromMaybe mempty e in
229+
when (("FATAL: password authentication failed" `isInfixOf` failureMessage) || ("no password supplied" `isInfixOf` failureMessage)) $ do
230+
observer $ ExitDBFatalError ServerAuthError err
231+
killThread mainThreadId
232+
err@(SQL.SessionUsageError (SQL.QueryError tpl _ (SQL.ResultError resultErr))) -> handleResultError err tpl resultErr
233+
-- Passing the empty template will not work for schema cache queries, see TODO further below.
234+
err@(SQL.SessionUsageError (SQL.PipelineError (SQL.ResultError resultErr))) -> handleResultError err mempty resultErr
235+
SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _)) -> pure ()
236+
SQL.SessionUsageError (SQL.PipelineError (SQL.ClientError _)) -> pure ()
237+
)
238+
239+
return res
240+
where
241+
handleResultError err tpl resultErr = do
233242
case resultErr of
234243
SQL.UnexpectedResult{} -> do
235244
observer $ ExitDBFatalError ServerPgrstBug err
@@ -262,12 +271,6 @@ usePool AppState{stateObserver=observer, stateMainThreadId=mainThreadId, ..} ses
262271
SQL.ServerError{} ->
263272
when (Error.status (Error.PgError False err) >= HTTP.status500) $
264273
observer $ QueryErrorCodeHighObs err
265-
err@(SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _))) ->
266-
-- An error on the client-side, usually indicates problems wth connection
267-
observer $ QueryErrorCodeHighObs err
268-
)
269-
270-
return res
271274

272275
-- | Flush the connection pool so that any future use of the pool will
273276
-- use connections freshly established after this call.

src/PostgREST/Error.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,22 @@ instance JSON.ToJSON SQL.UsageError where
526526

527527
instance ErrorBody SQL.UsageError where
528528
code (SQL.ConnectionUsageError _) = "PGRST000"
529+
code (SQL.SessionUsageError (SQL.PipelineError e)) = code e
529530
code (SQL.SessionUsageError (SQL.QueryError _ _ e)) = code e
530531
code SQL.AcquisitionTimeoutUsageError = "PGRST003"
531532

532533
message (SQL.ConnectionUsageError _) = "Database connection error. Retrying the connection."
534+
message (SQL.SessionUsageError (SQL.PipelineError e)) = message e
533535
message (SQL.SessionUsageError (SQL.QueryError _ _ e)) = message e
534536
message SQL.AcquisitionTimeoutUsageError = "Timed out acquiring connection from connection pool."
535537

536538
details (SQL.ConnectionUsageError e) = JSON.String . T.decodeUtf8 <$> e
539+
details (SQL.SessionUsageError (SQL.PipelineError e)) = details e
537540
details (SQL.SessionUsageError (SQL.QueryError _ _ e)) = details e
538541
details SQL.AcquisitionTimeoutUsageError = Nothing
539542

540543
hint (SQL.ConnectionUsageError _) = Nothing
544+
hint (SQL.SessionUsageError (SQL.PipelineError e)) = hint e
541545
hint (SQL.SessionUsageError (SQL.QueryError _ _ e)) = hint e
542546
hint SQL.AcquisitionTimeoutUsageError = Nothing
543547

@@ -586,8 +590,13 @@ instance ErrorBody SQL.CommandError where
586590
pgErrorStatus :: Bool -> SQL.UsageError -> HTTP.Status
587591
pgErrorStatus _ (SQL.ConnectionUsageError _) = HTTP.status503
588592
pgErrorStatus _ SQL.AcquisitionTimeoutUsageError = HTTP.status504
593+
pgErrorStatus _ (SQL.SessionUsageError (SQL.PipelineError (SQL.ClientError _))) = HTTP.status503
589594
pgErrorStatus _ (SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _))) = HTTP.status503
590-
pgErrorStatus authed (SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ResultError rError))) =
595+
pgErrorStatus authed (SQL.SessionUsageError (SQL.PipelineError (SQL.ResultError rError))) = mapSQLtoHTTP authed rError
596+
pgErrorStatus authed (SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ResultError rError))) = mapSQLtoHTTP authed rError
597+
598+
mapSQLtoHTTP :: Bool -> SQL.ResultError -> HTTP.Status
599+
mapSQLtoHTTP authed rError =
591600
case rError of
592601
(SQL.ServerError c m d _ _) ->
593602
case BS.unpack c of

src/PostgREST/Metrics.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ observationMetrics MetricsState{..} obs = case obs of
4747
(PoolAcqTimeoutObs _) -> do
4848
incCounter poolTimeouts
4949
(HasqlPoolObs (SQL.ConnectionObservation _ status)) -> case status of
50-
SQL.ReadyForUseConnectionStatus -> do
50+
SQL.ReadyForUseConnectionStatus _ -> do
5151
incGauge poolAvailable
5252
SQL.InUseConnectionStatus -> do
5353
decGauge poolAvailable

src/PostgREST/Observation.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ observationMessage = \case
139139
"Connection " <> show uuid <> (
140140
case status of
141141
SQL.ConnectingConnectionStatus -> " is being established"
142-
SQL.ReadyForUseConnectionStatus -> " is available"
142+
SQL.ReadyForUseConnectionStatus reason -> " is available due to " <> case reason of
143+
SQL.EstablishedConnectionReadyForUseReason -> "connection establishment"
144+
SQL.SessionFailedConnectionReadyForUseReason _ -> "session failure"
145+
SQL.SessionSucceededConnectionReadyForUseReason -> "session success"
143146
SQL.InUseConnectionStatus -> " is used"
144147
SQL.TerminatedConnectionStatus reason -> " is terminated due to " <> case reason of
145148
SQL.AgingConnectionTerminationReason -> "max lifetime"
146149
SQL.IdlenessConnectionTerminationReason -> "max idletime"
147150
SQL.ReleaseConnectionTerminationReason -> "release"
148151
SQL.NetworkErrorConnectionTerminationReason _ -> "network error" -- usage error is already logged, no need to repeat the same message.
152+
SQL.InitializationErrorTerminationReason _ -> "init failure"
149153
)
150154
PoolRequest ->
151155
"Trying to borrow a connection from pool"

0 commit comments

Comments
 (0)