Skip to content

Commit 612dfec

Browse files
chore(deps): update hasql to 1.8.1.4
1 parent 5f6f50d commit 612dfec

File tree

8 files changed

+112
-47
lines changed

8 files changed

+112
-47
lines changed

nix/overlays/haskell-packages.nix

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
self: super:
44
let
5-
inherit (self.haskell) lib;
5+
# inherit (self.haskell) lib;
66

77
overrides =
88
_: prev:
@@ -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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ library
110110
, either >= 4.4.1 && < 5.1
111111
, extra >= 1.7.0 && < 2.0
112112
, fuzzyset >= 0.2.4 && < 0.3
113-
, hasql >= 1.6.1.1 && < 1.7
113+
, hasql >= 1.7 && < 1.9
114114
, hasql-dynamic-statements >= 0.3.1 && < 0.4
115-
, hasql-notifications >= 0.2.2.2 && < 0.2.3
116-
, hasql-pool >= 1.0.1 && < 1.1
115+
, hasql-notifications >= 0.2.2.0 && < 0.3
116+
, hasql-pool >= 1.1 && < 1.3
117117
, hasql-transaction >= 1.0.1 && < 1.2
118118
, heredoc >= 0.2 && < 0.3
119119
, http-types >= 0.12.2 && < 0.13
@@ -128,8 +128,6 @@ library
128128
, network-uri >= 2.6.1 && < 2.8
129129
, optparse-applicative >= 0.13 && < 0.19
130130
, parsec >= 3.1.11 && < 3.2
131-
-- Technically unused, can be removed after updating to hasql >= 1.7
132-
, postgresql-libpq >= 0.10
133131
, prometheus-client >= 1.1.1 && < 1.2.0
134132
, protolude >= 0.3.1 && < 0.4
135133
, regex-tdfa >= 1.2.2 && < 1.4
@@ -265,7 +263,7 @@ test-suite spec
265263
, bytestring >= 0.10.8 && < 0.13
266264
, case-insensitive >= 1.2 && < 1.3
267265
, containers >= 0.5.7 && < 0.7
268-
, hasql-pool >= 1.0.1 && < 1.1
266+
, hasql-pool >= 1.0.1 && < 1.3
269267
, hasql-transaction >= 1.0.1 && < 1.2
270268
, heredoc >= 0.2 && < 0.3
271269
, hspec >= 2.3 && < 2.12

src/PostgREST/AppState.hs

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

219-
res <- SQL.use statePool sess
219+
res <- SQL.use statePool sess
220220

221-
observer PoolRequestFullfilled
221+
observer PoolRequestFullfilled
222222

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

271278
-- | Flush the connection pool so that any future use of the pool will
272279
-- 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
@@ -53,7 +53,7 @@ observationMetrics MetricsState{..} obs = case obs of
5353
(PoolAcqTimeoutObs _) -> do
5454
incCounter poolTimeouts
5555
(HasqlPoolObs (SQL.ConnectionObservation _ status)) -> case status of
56-
SQL.ReadyForUseConnectionStatus -> do
56+
SQL.ReadyForUseConnectionStatus _ -> do
5757
incGauge poolAvailable
5858
SQL.InUseConnectionStatus -> do
5959
decGauge poolAvailable

src/PostgREST/Observation.hs

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

stack.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ nix:
99

1010
extra-deps:
1111
- fuzzyset-0.2.4
12-
- hasql-pool-1.0.1
12+
- hasql-1.8.1.4
13+
- hasql-dynamic-statements-0.3.1.8
14+
- hasql-implicits-0.2.0.1
15+
- hasql-notifications-0.2.3.2
16+
- hasql-pool-1.2.0.3
17+
- hasql-transaction-1.1.1.2
1318
- jose-jwt-0.10.0
14-
- postgresql-libpq-0.10.1.0
19+
- postgresql-binary-0.14.0.1
20+
- postgresql-libpq-0.11.0.0
21+
- postgresql-libpq-configure-0.11

stack.yaml.lock

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,47 @@ packages:
1212
original:
1313
hackage: fuzzyset-0.2.4
1414
- completed:
15-
hackage: hasql-pool-1.0.1@sha256:3cfb4c7153a6c536ac7e126c17723e6d26ee03794954deed2d72bcc826d05a40,2302
15+
hackage: hasql-1.8.1.4@sha256:9f8b036b1485994da1fc804cead2bdf0eccebcb31fe109e8c0aaa49dea6ad72b,5696
1616
pantry-tree:
17-
sha256: d98e1269bdd60989b0eb0b84e1d5357eaa9f92821439d9f206663b7251ee95b2
18-
size: 799
17+
sha256: a429280972f8c8f4624b2e84ea550a05e1d9a9cd7d8b2cdbcf27253feb6f98a1
18+
size: 3438
1919
original:
20-
hackage: hasql-pool-1.0.1
20+
hackage: hasql-1.8.1.4
21+
- completed:
22+
hackage: hasql-dynamic-statements-0.3.1.8@sha256:7665dae003849430980b835f864c571f1a7aa8c8a2640876c94576955c98444e,2537
23+
pantry-tree:
24+
sha256: 68c29c16f70bf1450926c8e511a54755cebd25002c06d0664202b8913b523c15
25+
size: 595
26+
original:
27+
hackage: hasql-dynamic-statements-0.3.1.8
28+
- completed:
29+
hackage: hasql-implicits-0.2.0.1@sha256:63ca855a4b857e762d48757f6a9562a2cb9fd895c3d38c941260768278c4923c,1336
30+
pantry-tree:
31+
sha256: cb9e593c1579dd8de430cb587643896c39eff09e6c45a1432324e9d6af2ca876
32+
size: 264
33+
original:
34+
hackage: hasql-implicits-0.2.0.1
35+
- completed:
36+
hackage: hasql-notifications-0.2.3.2@sha256:547c1c677227b3063042f3af4d150dd224c1219545e936428da6d6b05e56c5fb,1998
37+
pantry-tree:
38+
sha256: 6e0427de378fe97da347ec977b0353001940e8f8ff772a310eb2acac95ef7b12
39+
size: 452
40+
original:
41+
hackage: hasql-notifications-0.2.3.2
42+
- completed:
43+
hackage: hasql-pool-1.2.0.3@sha256:27cfef3f4921c9cdaf4cae095f802c9977976a434842792d2b073537681b16c8,2389
44+
pantry-tree:
45+
sha256: f380573da2665b994fa9fb31e55c272f3757598f57f850fdb31d1b7fbe184a5e
46+
size: 982
47+
original:
48+
hackage: hasql-pool-1.2.0.3
49+
- completed:
50+
hackage: hasql-transaction-1.1.1.2@sha256:be4fb0e49da04f55c9bfbd5828f7025f1cf3165340ecf79b57ec286f4bde2368,2592
51+
pantry-tree:
52+
sha256: 41a8a96841e612787f2a744c49a57b5d5f4aa3fbaec3efe5ed1d37441f54c3b5
53+
size: 1027
54+
original:
55+
hackage: hasql-transaction-1.1.1.2
2156
- completed:
2257
hackage: jose-jwt-0.10.0@sha256:6ed175a01c721e317ceea15eb251a81de145c03711a977517935633a5cdec1d4,3546
2358
pantry-tree:
@@ -26,12 +61,26 @@ packages:
2661
original:
2762
hackage: jose-jwt-0.10.0
2863
- completed:
29-
hackage: postgresql-libpq-0.10.1.0@sha256:6b580c9d5068e78eecc13e655b2885c8e79cdacfca513c5d1e5a6b9dc61d9758,3166
64+
hackage: postgresql-binary-0.14.0.1@sha256:06366fd82deda89f9237b885e9493eafe0b9903d05c19761288b048dcc9a99ee,4027
65+
pantry-tree:
66+
sha256: ca58c715b5e5ad2abbfc1d87e3a620f27b93007591168acd2e60617880be35fa
67+
size: 1661
68+
original:
69+
hackage: postgresql-binary-0.14.0.1
70+
- completed:
71+
hackage: postgresql-libpq-0.11.0.0@sha256:ca7facdf755f7ad3950e75eee4a388f52179b027ca983be362c400ab0a37a4c4,2702
72+
pantry-tree:
73+
sha256: d401e0dd176fcbb8badb3ea9fd57614bb70c1a486cbe202c271a911f91d1556c
74+
size: 1048
75+
original:
76+
hackage: postgresql-libpq-0.11.0.0
77+
- completed:
78+
hackage: postgresql-libpq-configure-0.11@sha256:019c5d83da0b4dc0b4487e0e868f2eed5efa25e0688f5cfc2ba8191a80e527aa,1309
3079
pantry-tree:
31-
sha256: ae81e7628a8f3d1ef33ace71fa0845c073c003ca7f1150cc9d9ba1e55fc84236
32-
size: 1096
80+
sha256: 04a70f52cfacce71901efb1eafe3ae3103d133c1c4ee89ba7a51877c67503041
81+
size: 353
3382
original:
34-
hackage: postgresql-libpq-0.10.1.0
83+
hackage: postgresql-libpq-configure-0.11
3584
snapshots:
3685
- completed:
3786
sha256: 238fa745b64f91184f9aa518fe04bdde6552533d169b0da5256670df83a0f1a9

0 commit comments

Comments
 (0)