fix: kill postgrest main thread on admin server crash
Fixes #5096. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. From versio
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix admin server crashing without a way to recover by @taimoorzaeem in #5096
|
||||||
|
|
||||||
## [14.15] - 2026-07-13
|
## [14.15] - 2026-07-13
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Control.Monad.Extra (whenJust)
|
|||||||
import Network.Socket hiding (addrFamily)
|
import Network.Socket hiding (addrFamily)
|
||||||
import Network.Socket.ByteString
|
import Network.Socket.ByteString
|
||||||
|
|
||||||
import PostgREST.AppState (AppState, getConfig)
|
import PostgREST.AppState (AppState, getConfig, getMainThreadId)
|
||||||
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)
|
||||||
@@ -28,7 +28,7 @@ runAdmin appState maybeAdminSocket socketREST 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 socketREST
|
adminApp = admin appState socketREST
|
||||||
@@ -38,9 +38,9 @@ runAdmin appState maybeAdminSocket socketREST 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
|
killThread (getMainThreadId appState) -- Admin server crash is deemed unrecoverable, so we kill postgrest
|
||||||
|
|
||||||
-- | PostgREST admin application
|
-- | PostgREST admin application
|
||||||
admin :: AppState.AppState -> NS.Socket -> Wai.Application
|
admin :: AppState.AppState -> NS.Socket -> Wai.Application
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ observationMessage = \case
|
|||||||
AdminStartObs address ->
|
AdminStartObs address ->
|
||||||
"Admin server listening on " <> address
|
"Admin server listening on " <> address
|
||||||
AdminServerCrashedObs ex ->
|
AdminServerCrashedObs ex ->
|
||||||
"FAILURE: Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex
|
"Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex
|
||||||
AppStartObs ver ->
|
AppStartObs ver ->
|
||||||
"Starting PostgREST " <> T.decodeUtf8 ver <> "..."
|
"Starting PostgREST " <> T.decodeUtf8 ver <> "..."
|
||||||
AppServerAddressObs address ->
|
AppServerAddressObs address ->
|
||||||
|
|||||||
Reference in New Issue
Block a user