fix: don't hide error on LISTEN channel failure (#3323)
This commit is contained in:
@@ -22,6 +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
|
||||
- #3160, Fix using select= query parameter for custom media type handlers - @wolfgangwalther
|
||||
- #3237, Dump media handlers and timezones with --dump-schema - @wolfgangwalther
|
||||
- #3323, Don't hide error on LISTEN channel failure - @steve-chavez
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
||||
@@ -487,15 +487,16 @@ listener appState observer = do
|
||||
putIsListenerOn appState True
|
||||
SQL.listen db $ SQL.toPgIdentifier dbChannel
|
||||
SQL.waitForNotifications handleNotification db
|
||||
_ ->
|
||||
die $ "Could not listen for notifications on the " <> dbChannel <> " channel"
|
||||
Left err -> do
|
||||
observer $ DBListenerFail dbChannel err
|
||||
exitFailure
|
||||
where
|
||||
handleFinally _ False _ = do
|
||||
observer DBListenerFailNoRecoverObs
|
||||
handleFinally dbChannel False err = do
|
||||
observer $ DBListenerFailNoRecoverObs dbChannel err
|
||||
killThread (getMainThreadId appState)
|
||||
handleFinally dbChannel True _ = do
|
||||
handleFinally dbChannel True err = do
|
||||
-- if the thread dies, we try to recover
|
||||
observer $ DBListenerFailRecoverObs dbChannel
|
||||
observer $ DBListenerFailRecoverObs dbChannel err
|
||||
putIsListenerOn appState False
|
||||
-- assume the pool connection was also lost, call the connection worker
|
||||
connectionWorker appState
|
||||
|
||||
@@ -10,6 +10,7 @@ module PostgREST.Observation
|
||||
|
||||
import qualified Data.ByteString.Lazy as LBS
|
||||
import qualified Data.Text.Encoding as T
|
||||
import qualified Hasql.Connection as SQL
|
||||
import qualified Hasql.Pool as SQL
|
||||
import qualified Network.Socket as NS
|
||||
import Numeric (showFFloat)
|
||||
@@ -36,8 +37,9 @@ data Observation
|
||||
| ConnectionRetryObs Int
|
||||
| ConnectionPgVersionErrorObs SQL.UsageError
|
||||
| DBListenerStart Text
|
||||
| DBListenerFailNoRecoverObs
|
||||
| DBListenerFailRecoverObs Text
|
||||
| DBListenerFail Text SQL.ConnectionError
|
||||
| DBListenerFailNoRecoverObs Text (Either SomeException ())
|
||||
| DBListenerFailRecoverObs Text (Either SomeException ())
|
||||
| ConfigReadErrorObs
|
||||
| ConfigReadErrorFatalObs SQL.UsageError Text
|
||||
| ConfigReadErrorNotFatalObs SQL.UsageError
|
||||
@@ -81,10 +83,12 @@ observationMessage = \case
|
||||
jsonMessage usageErr
|
||||
DBListenerStart channel -> do
|
||||
"Listening for notifications on the " <> channel <> " channel"
|
||||
DBListenerFailNoRecoverObs ->
|
||||
"Automatic recovery disabled, exiting."
|
||||
DBListenerFailRecoverObs channel ->
|
||||
"Retrying listening for notifications on the " <> channel <> " channel.."
|
||||
DBListenerFail channel err -> do
|
||||
"Could not listen for notifications on the " <> channel <> " channel. " <> show err
|
||||
DBListenerFailNoRecoverObs channel err ->
|
||||
showListenerError err <> ". Automatic recovery disabled on the " <> channel <> " channel"
|
||||
DBListenerFailRecoverObs channel err ->
|
||||
showListenerError err <> ". Retrying listening for notifications on the " <> channel <> " channel.."
|
||||
ConfigReadErrorObs ->
|
||||
"An error ocurred when trying to query database settings for the config parameters"
|
||||
ConfigReadErrorFatalObs usageErr hint ->
|
||||
@@ -106,3 +110,7 @@ observationMessage = \case
|
||||
showMillis x = toS $ showFFloat (Just 1) (x * 1000) ""
|
||||
|
||||
jsonMessage err = T.decodeUtf8 . LBS.toStrict . Error.errorPayload $ Error.PgError False err
|
||||
|
||||
showListenerError :: Either SomeException () -> Text
|
||||
showListenerError (Left e) = show e
|
||||
showListenerError (Right _) = "Failed getting notifications" -- this should not happen as the listener will never finish with a Right result
|
||||
|
||||
Reference in New Issue
Block a user