fix(admin): log admin server exceptions and close admin socket
Admin server was crashing silently and requests hang indefinitely. With this fix, we are now logging the admin server exceptions and also close the socket afterwards so admin request don't hang. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
steve-chavez
parent
c98a8c2a29
commit
ae65768569
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. From versio
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix admin server not logging cause of failure by @taimoorzaeem in #5012
|
||||||
|
|
||||||
## [14.13] - 2026-06-04
|
## [14.13] - 2026-06-04
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
+13
-3
@@ -11,7 +11,8 @@ 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)
|
import PostgREST.AppState (AppState, getConfig)
|
||||||
|
import PostgREST.Config (AppConfig (..))
|
||||||
import PostgREST.MediaType (MediaType (..), toContentType)
|
import PostgREST.MediaType (MediaType (..), toContentType)
|
||||||
import PostgREST.Metrics (metricsToText)
|
import PostgREST.Metrics (metricsToText)
|
||||||
import PostgREST.Network (resolveSocketToAddress)
|
import PostgREST.Network (resolveSocketToAddress)
|
||||||
@@ -24,13 +25,22 @@ import Protolude
|
|||||||
|
|
||||||
runAdmin :: AppState -> Maybe NS.Socket -> NS.Socket -> Warp.Settings -> IO ()
|
runAdmin :: AppState -> Maybe NS.Socket -> NS.Socket -> Warp.Settings -> IO ()
|
||||||
runAdmin appState maybeAdminSocket socketREST settings = do
|
runAdmin appState maybeAdminSocket socketREST settings = do
|
||||||
|
conf <- getConfig appState
|
||||||
whenJust maybeAdminSocket $ \adminSocket -> do
|
whenJust maybeAdminSocket $ \adminSocket -> do
|
||||||
address <- resolveSocketToAddress adminSocket
|
address <- resolveSocketToAddress adminSocket
|
||||||
observer $ AdminStartObs address
|
void . forkIO $ handle (onError adminSocket) $
|
||||||
void . forkIO $ Warp.runSettingsSocket settings adminSocket adminApp
|
Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp
|
||||||
where
|
where
|
||||||
adminApp = admin appState socketREST
|
adminApp = admin appState socketREST
|
||||||
observer = AppState.getObserver appState
|
observer = AppState.getObserver appState
|
||||||
|
adminServerSettings config addr =
|
||||||
|
settings
|
||||||
|
& Warp.setBeforeMainLoop (observer $ AdminStartObs addr)
|
||||||
|
& maybe identity Warp.setPort (configAdminServerPort config)
|
||||||
|
|
||||||
|
onError adminSock ex = do
|
||||||
|
observer $ AdminServerCrashedObs ex
|
||||||
|
NS.close adminSock -- we close the socket so request doesn't hang
|
||||||
|
|
||||||
-- | PostgREST admin application
|
-- | PostgREST admin application
|
||||||
admin :: AppState.AppState -> NS.Socket -> Wai.Application
|
admin :: AppState.AppState -> NS.Socket -> Wai.Application
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ observationMessage :: Observation -> Text
|
|||||||
observationMessage = \case
|
observationMessage = \case
|
||||||
AdminStartObs address ->
|
AdminStartObs address ->
|
||||||
"Admin server listening on " <> address
|
"Admin server listening on " <> address
|
||||||
|
AdminServerCrashedObs ex ->
|
||||||
|
"FAILURE: 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 ->
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import Protolude hiding (toList)
|
|||||||
|
|
||||||
data Observation
|
data Observation
|
||||||
= AdminStartObs Text
|
= AdminStartObs Text
|
||||||
|
| AdminServerCrashedObs SomeException
|
||||||
| AppStartObs ByteString
|
| AppStartObs ByteString
|
||||||
| AppServerAddressObs Text
|
| AppServerAddressObs Text
|
||||||
| ExitUnsupportedPgVersion PgVersion PgVersion
|
| ExitUnsupportedPgVersion PgVersion PgVersion
|
||||||
|
|||||||
Reference in New Issue
Block a user