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
18646a6c03
commit
b967a5033a
@@ -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
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -25,6 +25,7 @@ import Protolude hiding (toList)
|
||||
|
||||
data Observation
|
||||
= AdminStartObs Text
|
||||
| AdminServerCrashedObs SomeException
|
||||
| AppStartObs ByteString
|
||||
| AppServerAddressObs Text
|
||||
| ExitUnsupportedPgVersion PgVersion PgVersion
|
||||
|
||||
Reference in New Issue
Block a user