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