Merge pull request #3823 from urbit/kh-eyre-shutdown

king: cancel http servers immediately on shutdown.
This commit is contained in:
Elliot Glaysher 2020-10-30 10:23:25 -04:00 committed by GitHub
commit e7192d9c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -344,9 +344,9 @@ eyre env who plan isFake stderr = (initialEvents, runHttpServer)
kill :: HasLogFunc e => Serv -> RIO e ()
kill Serv{..} = do
atomically (leaveMultiEyre multi who)
atomically (saKil sLop)
atomically (saKil sIns)
for_ sSec (\sec -> atomically (saKil sec))
io (saKil sLop)
io (saKil sIns)
io $ for_ sSec (\sec -> (saKil sec))
io (removePortsFile sPortsFile)
restart :: Drv -> HttpServerConf -> RIO e Serv

View File

@ -45,7 +45,7 @@ data MultiEyreApi = MultiEyreApi
, meaPlan :: TVar (Map Ship OnMultiReq)
, meaCanc :: TVar (Map Ship OnMultiKil)
, meaTlsC :: TVar (Map Ship (TlsConfig, Credential))
, meaKill :: STM ()
, meaKill :: IO ()
}

View File

@ -54,7 +54,7 @@ import qualified Urbit.Vere.Eyre.Wai as E
-- Internal Types --------------------------------------------------------------
data ServApi = ServApi
{ saKil :: STM ()
{ saKil :: IO ()
, saPor :: STM W.Port
}
@ -332,14 +332,12 @@ getFirstTlsConfig (MTC var) = do
realServ :: HasLogFunc e => TVar E.LiveReqs -> ServConf -> RIO e ServApi
realServ vLive conf@ServConf {..} = do
logInfo (displayShow ("EYRE", "SERV", "Running Real Server"))
kil <- newEmptyTMVarIO
por <- newEmptyTMVarIO
tid <- async (runServ por)
_ <- async (atomically (takeTMVar kil) >> cancel tid)
pure $ ServApi
{ saKil = void (tryPutTMVar kil ())
{ saKil = cancel tid
, saPor = readTMVar por
}
where