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:
Taimoor Zaeem
2026-06-29 12:43:54 -05:00
committed by Steve Chavez
parent 18646a6c03
commit b967a5033a
4 changed files with 10 additions and 1 deletions
+6 -1
View File
@@ -28,7 +28,8 @@ runAdmin appState maybeAdminSocket getSocketREST settings = do
conf <- getConfig appState
whenJust maybeAdminSocket $ \adminSocket -> do
address <- resolveSocketToAddress adminSocket
void . forkIO $ Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp
void . forkIO $ handle (onError adminSocket) $
Warp.runSettingsSocket (adminServerSettings conf address) adminSocket adminApp
where
adminApp = admin appState getSocketREST
observer = AppState.getObserver appState
@@ -37,6 +38,10 @@ runAdmin appState maybeAdminSocket getSocketREST settings = do
& 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
admin :: AppState.AppState -> IO (Maybe NS.Socket) -> Wai.Application
admin appState getSocketREST req respond = do
+2
View File
@@ -132,6 +132,8 @@ observationMessages :: Observation -> [Text]
observationMessages = \case
AdminStartObs address ->
pure $ "Admin server listening on " <> address
AdminServerCrashedObs ex ->
pure $ "FAILURE: Admin server crashed unexpectedly: " <> (showOnSingleLine '\t' . show) ex
AppStartObs ver ->
pure $ "Starting PostgREST " <> T.decodeUtf8 ver <> "..."
AppServerAddressObs address ->
+1
View File
@@ -25,6 +25,7 @@ import Protolude hiding (toList)
data Observation
= AdminStartObs Text
| AdminServerCrashedObs SomeException
| AppStartObs ByteString
| AppServerAddressObs Text
| ExitUnsupportedPgVersion PgVersion PgVersion