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
|
- #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
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@@ -487,15 +487,16 @@ listener appState observer = do
|
|||||||
putIsListenerOn appState True
|
putIsListenerOn appState True
|
||||||
SQL.listen db $ SQL.toPgIdentifier dbChannel
|
SQL.listen db $ SQL.toPgIdentifier dbChannel
|
||||||
SQL.waitForNotifications handleNotification db
|
SQL.waitForNotifications handleNotification db
|
||||||
_ ->
|
Left err -> do
|
||||||
die $ "Could not listen for notifications on the " <> dbChannel <> " channel"
|
observer $ DBListenerFail dbChannel err
|
||||||
|
exitFailure
|
||||||
where
|
where
|
||||||
handleFinally _ False _ = do
|
handleFinally dbChannel False err = do
|
||||||
observer DBListenerFailNoRecoverObs
|
observer $ DBListenerFailNoRecoverObs dbChannel err
|
||||||
killThread (getMainThreadId appState)
|
killThread (getMainThreadId appState)
|
||||||
handleFinally dbChannel True _ = 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
|
observer $ DBListenerFailRecoverObs 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
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ module PostgREST.Observation
|
|||||||
|
|
||||||
import qualified Data.ByteString.Lazy as LBS
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
|
import qualified Hasql.Connection as SQL
|
||||||
import qualified Hasql.Pool as SQL
|
import qualified Hasql.Pool as SQL
|
||||||
import qualified Network.Socket as NS
|
import qualified Network.Socket as NS
|
||||||
import Numeric (showFFloat)
|
import Numeric (showFFloat)
|
||||||
@@ -36,8 +37,9 @@ data Observation
|
|||||||
| ConnectionRetryObs Int
|
| ConnectionRetryObs Int
|
||||||
| ConnectionPgVersionErrorObs SQL.UsageError
|
| ConnectionPgVersionErrorObs SQL.UsageError
|
||||||
| DBListenerStart Text
|
| DBListenerStart Text
|
||||||
| DBListenerFailNoRecoverObs
|
| DBListenerFail Text SQL.ConnectionError
|
||||||
| DBListenerFailRecoverObs Text
|
| DBListenerFailNoRecoverObs Text (Either SomeException ())
|
||||||
|
| DBListenerFailRecoverObs Text (Either SomeException ())
|
||||||
| ConfigReadErrorObs
|
| ConfigReadErrorObs
|
||||||
| ConfigReadErrorFatalObs SQL.UsageError Text
|
| ConfigReadErrorFatalObs SQL.UsageError Text
|
||||||
| ConfigReadErrorNotFatalObs SQL.UsageError
|
| ConfigReadErrorNotFatalObs SQL.UsageError
|
||||||
@@ -81,10 +83,12 @@ observationMessage = \case
|
|||||||
jsonMessage usageErr
|
jsonMessage usageErr
|
||||||
DBListenerStart channel -> do
|
DBListenerStart channel -> do
|
||||||
"Listening for notifications on the " <> channel <> " channel"
|
"Listening for notifications on the " <> channel <> " channel"
|
||||||
DBListenerFailNoRecoverObs ->
|
DBListenerFail channel err -> do
|
||||||
"Automatic recovery disabled, exiting."
|
"Could not listen for notifications on the " <> channel <> " channel. " <> show err
|
||||||
DBListenerFailRecoverObs channel ->
|
DBListenerFailNoRecoverObs channel err ->
|
||||||
"Retrying listening for notifications on the " <> channel <> " channel.."
|
showListenerError err <> ". Automatic recovery disabled on the " <> channel <> " channel"
|
||||||
|
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 ->
|
||||||
@@ -106,3 +110,7 @@ observationMessage = \case
|
|||||||
showMillis x = toS $ showFFloat (Just 1) (x * 1000) ""
|
showMillis x = toS $ showFFloat (Just 1) (x * 1000) ""
|
||||||
|
|
||||||
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 (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