Skip to content

Commit 2998546

Browse files
chore(deps): update hasql to 1.8.1.4
1 parent 2b19179 commit 2998546

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
@@ -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
@@ -125,8 +125,6 @@ library
125125
, network-uri >= 2.6.1 && < 2.8
126126
, optparse-applicative >= 0.13 && < 0.19
127127
, parsec >= 3.1.11 && < 3.2
128-
-- Technically unused, can be removed after updating to hasql >= 1.7
129-
, postgresql-libpq >= 0.10
130128
, prometheus-client >= 1.1.1 && < 1.2.0
131129
, protolude >= 0.3.1 && < 0.4
132130
, regex-tdfa >= 1.2.2 && < 1.4
@@ -257,7 +255,7 @@ test-suite spec
257255
, bytestring >= 0.10.8 && < 0.13
258256
, case-insensitive >= 1.2 && < 1.3
259257
, containers >= 0.5.7 && < 0.7
260-
, hasql-pool >= 1.0.1 && < 1.1
258+
, hasql-pool >= 1.0.1 && < 1.3
261259
, hasql-transaction >= 1.0.1 && < 1.2
262260
, heredoc >= 0.2 && < 0.3
263261
, hspec >= 2.3 && < 2.12

src/PostgREST/AppState.hs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,34 @@ 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))) ->
233+
handleResultError err tpl resultErr
234+
err@(SQL.SessionUsageError (SQL.PipelineError (SQL.ResultError resultErr))) ->
235+
-- Passing the empty template will not work for schema cache queries, see TODO further below.
236+
handleResultError err mempty resultErr
237+
err@(SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _))) ->
238+
-- An error on the client-side, usually indicates problems with connection
239+
observer $ QueryErrorCodeHighObs err
240+
SQL.SessionUsageError (SQL.PipelineError (SQL.ClientError _)) -> pure ()
241+
)
242+
243+
return res
244+
where
245+
handleResultError err tpl resultErr = do
233246
case resultErr of
234247
SQL.UnexpectedResult{} -> do
235248
observer $ ExitDBFatalError ServerPgrstBug err
@@ -262,12 +275,6 @@ usePool AppState{stateObserver=observer, stateMainThreadId=mainThreadId, ..} ses
262275
SQL.ServerError{} ->
263276
when (Error.status (Error.PgError False err) >= HTTP.status500) $
264277
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
271278

272279
-- | Flush the connection pool so that any future use of the pool will
273280
-- 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"

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)