fix: kill postgrest main thread on admin server crash
Fixes #5096. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user