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 22:00:56 +05:00
parent 6206f55673
commit 85c8828c0d
3 changed files with 9 additions and 5 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ import Control.Monad.Extra (whenJust)
import Network.Socket hiding (addrFamily)
import Network.Socket.ByteString
import PostgREST.AppState (AppState, getConfig)
import PostgREST.AppState (AppState, getConfig, getMainThreadId)
import PostgREST.Config (AppConfig (..))
import PostgREST.MediaType (MediaType (..), toContentType)
import PostgREST.Metrics (metricsToText)
@@ -28,7 +28,7 @@ runAdmin appState maybeAdminSocket socketREST 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 socketREST
@@ -38,9 +38,9 @@ runAdmin appState maybeAdminSocket socketREST 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
killThread (getMainThreadId appState) -- Admin server crash is deemed unrecoverable, so we kill postgrest
-- | PostgREST admin application
admin :: AppState.AppState -> NS.Socket -> Wai.Application