Skip to content

Commit c96dc3e

Browse files
taimoorzaeemsteve-chavez
authored andcommitted
fix: log 503 client error to stderr
1 parent 3f78615 commit c96dc3e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2525
+ Fixed `"column <json_aggregate>.<alias> does not exist"` error when selecting `?select=...table(aias:count())`
2626
- #3727, Clarify "listening" logs - @steve-chavez
2727
- #3795, Clarify `Accept: vnd.pgrst.object` error message - @steve-chavez
28+
- #3841, Log `503` client error to stderr - @taimoorzaeem
2829

2930
### Changed
3031

src/PostgREST/AppState.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ usePool AppState{stateObserver=observer, stateMainThreadId=mainThreadId, ..} ses
261261
SQL.ServerError{} ->
262262
when (Error.status (Error.PgError False err) >= HTTP.status500) $
263263
observer $ QueryErrorCodeHighObs err
264-
SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _)) ->
265-
pure ()
264+
err@(SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ClientError _))) ->
265+
-- An error on the client-side, usually indicates problems wth connection
266+
observer $ QueryErrorCodeHighObs err
266267
)
267268

268269
return res

test/io/test_io.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,3 +1696,22 @@ def test_jwt_cache_purges_expired_entries(defaultenv):
16961696
response = postgrest.session.get("/authors_only", headers=hdrs3)
16971697

16981698
assert response.status_code == 200
1699+
1700+
1701+
def test_pgrst_log_503_client_error_to_stderr(defaultenv):
1702+
"PostgREST should log 503 errors to stderr"
1703+
1704+
env = {
1705+
**defaultenv,
1706+
"PGAPPNAME": "test-io",
1707+
}
1708+
1709+
with run(env=env) as postgrest:
1710+
1711+
postgrest.session.get("/rpc/terminate_pgrst?appname=test-io")
1712+
1713+
output = postgrest.read_stdout(nlines=6)
1714+
1715+
log_message = '{"code":"PGRST001","details":"no connection to the server\\n","hint":null,"message":"Database client error. Retrying the connection."}\n'
1716+
1717+
assert any(log_message in line for line in output)

0 commit comments

Comments
 (0)