diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9113001..15472f581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file. From versio - Stop reporting 503s errors unnecessarily while the schema cache is loading at startup by @mkleczek in #4880 - Fix responding with `Something went wrong` on Admin server when under EMFILE by @mkleczek in #5077 - Fix schema cache dump missing RPC transaction isolation level by @taimoorzaeem in #5079 +- Fix admin server crashing without a way to recover by @taimoorzaeem in #5096 ### Changed diff --git a/src/library/PostgREST/Admin.hs b/src/library/PostgREST/Admin.hs index 8438a795c..0dd90e122 100644 --- a/src/library/PostgREST/Admin.hs +++ b/src/library/PostgREST/Admin.hs @@ -9,7 +9,7 @@ import qualified Network.Wai.Handler.Warp as Warp import Control.Monad.Extra (whenJust) -import PostgREST.AppState (AppState, getConfig) +import PostgREST.AppState (AppState, getConfig, killApp) import PostgREST.Config (AppConfig (..)) import PostgREST.MediaType (MediaType (..), toContentType) import PostgREST.Metrics (metricsToText) @@ -26,7 +26,7 @@ runAdmin appState maybeAdminSocket checkMainAppLive settings = do conf <- getConfig appState whenJust maybeAdminSocket $ \adminSocket -> do address <- resolveSocketToAddress adminSocket - void . forkIO $ handle (onError adminSocket) $ + void . forkIO $ handle onError $ Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp where adminApp = admin appState checkMainAppLive @@ -36,9 +36,9 @@ runAdmin appState maybeAdminSocket checkMainAppLive settings = do & Warp.setBeforeMainLoop (observer $ AdminStartObs addr) & maybe identity Warp.setPort (configAdminServerPort config) - onError adminSock ex = do + onError ex = do observer $ AdminServerCrashedObs ex - NS.close adminSock -- we close the socket so request doesn't hang + killApp appState -- Admin server crash is deemed unrecoverable, so we kill postgrest -- | PostgREST admin application admin :: AppState.AppState -> IO Bool -> Wai.Application diff --git a/src/library/PostgREST/Logger.hs b/src/library/PostgREST/Logger.hs index 42a23e43e..70e3c905e 100644 --- a/src/library/PostgREST/Logger.hs +++ b/src/library/PostgREST/Logger.hs @@ -131,7 +131,7 @@ observationMessages = \case AdminStartObs address -> pure $ "Admin server listening on " <> address AdminServerCrashedObs ex -> - pure $ "FAILURE: Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex + pure $ "Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex AppStartObs ver -> pure $ "Starting PostgREST " <> T.decodeUtf8 ver <> "..." AppServerAddressObs address ->