king: address joe on fds/seppuku

This commit is contained in:
pilfer-pandex 2021-03-21 21:27:50 -04:00
parent 72f0201de3
commit 1a39dac437
3 changed files with 23 additions and 9 deletions

View File

@ -704,9 +704,13 @@ main = do
Sys.installHandler sig (Sys.Catch onKillSig) Nothing
setRLimits = do
nofiles <- Sys.getResourceLimit Sys.ResourceOpenFiles
openFiles <- Sys.getResourceLimit Sys.ResourceOpenFiles
let soft = case Sys.hardLimit openFiles of
Sys.ResourceLimit lim -> Sys.ResourceLimit lim
Sys.ResourceLimitInfinity -> Sys.ResourceLimit 10240 -- macOS
Sys.ResourceLimitUnknown -> Sys.ResourceLimit 10240
Sys.setResourceLimit Sys.ResourceOpenFiles
nofiles { Sys.softLimit = Sys.ResourceLimit 10240 }
openFiles { Sys.softLimit = soft }
verboseLogging :: CLI.Cmd -> Bool
verboseLogging = \case

View File

@ -363,7 +363,7 @@ eyre env who plan isFake stderr sub = (initialEvents, runHttpServer)
logInfo "Restarting http server"
let onFatal = runRIO env $ do
-- XX instead maybe restart following logic under HSESetConfig below
stderr "You've been DDoSed. Please restart your ship."
stderr "A web server problem has occurred. Please restart your ship."
view killKingActionL >>= atomically
let startAct = startServ who isFake conf plan stderr onFatal sub
res <- fromEither =<< restartService var startAct kill

View File

@ -264,18 +264,28 @@ startServer typ hos por sok red vLive onFatal = do
SHLocalhost -> "127.0.0.1"
SHAnyHostOk -> "*"
let handler r e
let handler r e = do
when (isFatal e) $ do
runRIO envir $ logError $ display $ msg r e
onFatal
when (W.defaultShouldDisplayException e) $ do
runRIO envir $ logWarn $ display $ msg r e
isFatal e
| Just (IOError {ioe_type = ResourceExhausted}) <- fromException e
= runRIO envir $ do
logError (displayShow e)
io onFatal
| otherwise = W.defaultOnException r e
= True
| otherwise = False
msg r e = case r of
Just r -> "eyre: failed request from " <> (tshow $ W.remoteHost r)
<> " for " <> (tshow $ W.rawPathInfo r) <> ": " <> tshow e
Nothing -> "eyre: server exception: " <> tshow e
let opts =
W.defaultSettings
& W.setHost host
& W.setPort (fromIntegral por)
& W.setTimeout (5 * 60)
& W.setTimeout 30
& W.setOnException handler
-- TODO build Eyre.Site.app in pier, thread through here