fix: kill postgrest main thread on admin server crash

Fixes #5096.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
Taimoor Zaeem
2026-07-21 20:53:40 +05:00
parent 080abcb695
commit 178b1d3e38
3 changed files with 6 additions and 5 deletions
+1
View File
@@ -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 - 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 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 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 ### Changed
+4 -4
View File
@@ -9,7 +9,7 @@ import qualified Network.Wai.Handler.Warp as Warp
import Control.Monad.Extra (whenJust) import Control.Monad.Extra (whenJust)
import PostgREST.AppState (AppState, getConfig) import PostgREST.AppState (AppState, getConfig, killApp)
import PostgREST.Config (AppConfig (..)) import PostgREST.Config (AppConfig (..))
import PostgREST.MediaType (MediaType (..), toContentType) import PostgREST.MediaType (MediaType (..), toContentType)
import PostgREST.Metrics (metricsToText) import PostgREST.Metrics (metricsToText)
@@ -26,7 +26,7 @@ runAdmin appState maybeAdminSocket checkMainAppLive settings = do
conf <- getConfig appState conf <- getConfig appState
whenJust maybeAdminSocket $ \adminSocket -> do whenJust maybeAdminSocket $ \adminSocket -> do
address <- resolveSocketToAddress adminSocket address <- resolveSocketToAddress adminSocket
void . forkIO $ handle (onError adminSocket) $ void . forkIO $ handle onError $
Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp
where where
adminApp = admin appState checkMainAppLive adminApp = admin appState checkMainAppLive
@@ -36,9 +36,9 @@ runAdmin appState maybeAdminSocket checkMainAppLive settings = do
& Warp.setBeforeMainLoop (observer $ AdminStartObs addr) & Warp.setBeforeMainLoop (observer $ AdminStartObs addr)
& maybe identity Warp.setPort (configAdminServerPort config) & maybe identity Warp.setPort (configAdminServerPort config)
onError adminSock ex = do onError ex = do
observer $ AdminServerCrashedObs ex 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 -- | PostgREST admin application
admin :: AppState.AppState -> IO Bool -> Wai.Application admin :: AppState.AppState -> IO Bool -> Wai.Application
+1 -1
View File
@@ -131,7 +131,7 @@ observationMessages = \case
AdminStartObs address -> AdminStartObs address ->
pure $ "Admin server listening on " <> address pure $ "Admin server listening on " <> address
AdminServerCrashedObs ex -> AdminServerCrashedObs ex ->
pure $ "FAILURE: Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex pure $ "Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex
AppStartObs ver -> AppStartObs ver ->
pure $ "Starting PostgREST " <> T.decodeUtf8 ver <> "..." pure $ "Starting PostgREST " <> T.decodeUtf8 ver <> "..."
AppServerAddressObs address -> AppServerAddressObs address ->