From c785e2f23ec0c267e573be939ba5c54fd1fe692e Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Tue, 6 Jun 2023 14:05:38 -0500 Subject: [PATCH] feat: recover on pg_terminate_backend --- CHANGELOG.md | 1 + src/PostgREST/AppState.hs | 5 ++--- src/PostgREST/Error.hs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f256e2140d..b9ccda1228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #2703, Add pre-config function - @steve-chavez + New config option `db-pre-config`(empty by default) + Allows using the in-database configuration without SUPERUSER + - #2781, Start automatic connection recovery when pool connections are closed with pg_terminate_backend - @steve-chavez ### Fixed diff --git a/src/PostgREST/AppState.hs b/src/PostgREST/AppState.hs index f1adaf6324..6245f164c9 100644 --- a/src/PostgREST/AppState.hs +++ b/src/PostgREST/AppState.hs @@ -24,8 +24,7 @@ module PostgREST.AppState , runListener ) where -import qualified Data.ByteString as BS -import qualified Data.ByteString.Char8 as BS8 +import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as LBS import Data.Either.Combinators (whenLeft) import qualified Data.Text.Encoding as T @@ -456,7 +455,7 @@ checkIsFatal (SQL.ConnectionUsageError e) where isAuthFailureMessage = ("FATAL: password authentication failed" `isInfixOf` failureMessage) || ("no password supplied" `isInfixOf` failureMessage) - failureMessage = BS8.unpack $ fromMaybe mempty e + failureMessage = BS.unpack $ fromMaybe mempty e checkIsFatal(SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ResultError serverError))) = case serverError of -- Check for a syntax error (42601 is the pg code). This would mean the error is on our part somehow, so we treat it as fatal. diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index 1e76b09993..6e0d72d6f6 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -428,6 +428,7 @@ pgErrorStatus authed (SQL.SessionUsageError (SQL.QueryError _ _ (SQL.ResultError '5':'3':_ -> HTTP.status503 -- insufficient resources '5':'4':_ -> HTTP.status413 -- too complex '5':'5':_ -> HTTP.status500 -- obj not on prereq state + '5':'7':'P':'0':'1':_ -> HTTP.status503 -- terminating connection due to administrator command '5':'7':_ -> HTTP.status500 -- operator intervention '5':'8':_ -> HTTP.status500 -- system error 'F':'0':_ -> HTTP.status500 -- conf file error