fix: upgrade hasql-notifications to show error

This commit is contained in:
steve-chavez
2024-03-13 11:14:11 -05:00
committed by Steve Chavez
parent 00f5780415
commit 86e15dbb77
4 changed files with 25 additions and 13 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3224, Return status code 406 for non-accepted media type instead of code 415 - @wolfgangwalther - #3224, Return status code 406 for non-accepted media type instead of code 415 - @wolfgangwalther
- #3160, Fix using select= query parameter for custom media type handlers - @wolfgangwalther - #3160, Fix using select= query parameter for custom media type handlers - @wolfgangwalther
- #3237, Dump media handlers and timezones with --dump-schema - @wolfgangwalther - #3237, Dump media handlers and timezones with --dump-schema - @wolfgangwalther
- #3323, Don't hide error on LISTEN channel failure - @steve-chavez - #3323, #3324, Don't hide error on LISTEN channel failure - @steve-chavez
### Deprecated ### Deprecated
+14 -2
View File
@@ -19,15 +19,18 @@ let
# #
# To temporarily pin unreleased versions from GitHub: # To temporarily pin unreleased versions from GitHub:
# <name> = # <name> =
# prev.callCabal2nixWithOptions "<name>" (super.fetchFromGitHub { # lib.dontCheck (prev.callCabal2nixWithOptions "<name>" (super.fetchFromGitHub {
# owner = "<owner>"; # owner = "<owner>";
# repo = "<repo>"; # repo = "<repo>";
# rev = "<commit>"; # rev = "<commit>";
# sha256 = "<sha256>"; # sha256 = "<sha256>";
# }) "--subpath=<subpath>" {}; # }) "--subpath=." {});
# #
# To fill in the sha256: # To fill in the sha256:
# update-nix-fetchgit nix/overlays/haskell-packages.nix # update-nix-fetchgit nix/overlays/haskell-packages.nix
#
# Nowadays you can just delete the sha256 attribute above and nix will assume a fake sha.
# Once you build the derivation it will suggest the correct sha.
configurator-pg = configurator-pg =
prev.callHackageDirect prev.callHackageDirect
@@ -48,6 +51,15 @@ let
hasql-pool = lib.dontCheck prev.hasql-pool_0_10; hasql-pool = lib.dontCheck prev.hasql-pool_0_10;
hasql-notifications = lib.dontCheck (prev.callHackageDirect
{
pkg = "hasql-notifications";
ver = "0.2.1.0";
sha256 = "sha256-MEIirDKR81KpiBOnWJbVInWevL6Kdb/XD1Qtd8e6KsQ=";
}
{ }
);
}; };
in in
{ {
+2 -2
View File
@@ -492,11 +492,11 @@ listener appState observer = do
exitFailure exitFailure
where where
handleFinally dbChannel False err = do handleFinally dbChannel False err = do
observer $ DBListenerFailNoRecoverObs dbChannel err observer $ DBListenerFailRecoverObs False dbChannel err
killThread (getMainThreadId appState) killThread (getMainThreadId appState)
handleFinally dbChannel True err = do handleFinally dbChannel True err = do
-- if the thread dies, we try to recover -- if the thread dies, we try to recover
observer $ DBListenerFailRecoverObs dbChannel err observer $ DBListenerFailRecoverObs True dbChannel err
putIsListenerOn appState False putIsListenerOn appState False
-- assume the pool connection was also lost, call the connection worker -- assume the pool connection was also lost, call the connection worker
connectionWorker appState connectionWorker appState
+8 -8
View File
@@ -9,6 +9,7 @@ module PostgREST.Observation
) where ) where
import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as T
import qualified Data.Text.Encoding as T import qualified Data.Text.Encoding as T
import qualified Hasql.Connection as SQL import qualified Hasql.Connection as SQL
import qualified Hasql.Pool as SQL import qualified Hasql.Pool as SQL
@@ -38,8 +39,7 @@ data Observation
| ConnectionPgVersionErrorObs SQL.UsageError | ConnectionPgVersionErrorObs SQL.UsageError
| DBListenerStart Text | DBListenerStart Text
| DBListenerFail Text SQL.ConnectionError | DBListenerFail Text SQL.ConnectionError
| DBListenerFailNoRecoverObs Text (Either SomeException ()) | DBListenerFailRecoverObs Bool Text (Either SomeException ())
| DBListenerFailRecoverObs Text (Either SomeException ())
| ConfigReadErrorObs | ConfigReadErrorObs
| ConfigReadErrorFatalObs SQL.UsageError Text | ConfigReadErrorFatalObs SQL.UsageError Text
| ConfigReadErrorNotFatalObs SQL.UsageError | ConfigReadErrorNotFatalObs SQL.UsageError
@@ -85,10 +85,8 @@ observationMessage = \case
"Listening for notifications on the " <> channel <> " channel" "Listening for notifications on the " <> channel <> " channel"
DBListenerFail channel err -> do DBListenerFail channel err -> do
"Could not listen for notifications on the " <> channel <> " channel. " <> show err "Could not listen for notifications on the " <> channel <> " channel. " <> show err
DBListenerFailNoRecoverObs channel err -> DBListenerFailRecoverObs recover channel err ->
showListenerError err <> ". Automatic recovery disabled on the " <> channel <> " channel" "Could not listen for notifications on the " <> channel <> " channel. " <> showListenerError err <> (if recover then " Retrying listening for notifications.." else mempty)
DBListenerFailRecoverObs channel err ->
showListenerError err <> ". Retrying listening for notifications on the " <> channel <> " channel.."
ConfigReadErrorObs -> ConfigReadErrorObs ->
"An error ocurred when trying to query database settings for the config parameters" "An error ocurred when trying to query database settings for the config parameters"
ConfigReadErrorFatalObs usageErr hint -> ConfigReadErrorFatalObs usageErr hint ->
@@ -112,5 +110,7 @@ observationMessage = \case
jsonMessage err = T.decodeUtf8 . LBS.toStrict . Error.errorPayload $ Error.PgError False err jsonMessage err = T.decodeUtf8 . LBS.toStrict . Error.errorPayload $ Error.PgError False err
showListenerError :: Either SomeException () -> Text showListenerError :: Either SomeException () -> Text
showListenerError (Left e) = show e showListenerError (Right _) = "Failed getting notifications" -- should not happen as the listener will never finish (hasql-notifications uses `forever` internally) with a Right result
showListenerError (Right _) = "Failed getting notifications" -- this should not happen as the listener will never finish with a Right result showListenerError (Left e) =
let showOnSingleLine txt = T.intercalate " " $ T.filter (/= '\t') <$> T.lines txt in -- the errors from hasql-notifications come intercalated with "\t\n"
showOnSingleLine $ show e