Make sure we close HTTP sockets on close (or reconfigure).

This commit is contained in:
Benjamin Summers 2019-12-21 18:24:54 -08:00
parent 2e8defccc1
commit 06934959ca

View File

@ -93,6 +93,9 @@ data Serv = Serv
, sLoopTid :: Async ()
, sHttpTid :: Async ()
, sHttpsTid :: Maybe (Async ())
, sLoopSock :: Net.Socket
, sHttpSock :: Net.Socket
, sHttpsSock :: Net.Socket
, sPorts :: Ports
, sPortsFile :: FilePath
, sLiveReqs :: TVar LiveReqs
@ -486,13 +489,19 @@ startServ isFake conf plan = do
logDebug "Finished started HTTP Servers"
pure $ Serv sId conf loopTid httpTid httpsTid por fil liv
pure $ Serv sId conf
loopTid httpTid httpsTid
httpSock httpsSock loopSock
por fil liv
killServ :: HasLogFunc e => Serv -> RIO e ()
killServ Serv{..} = do
cancel sLoopTid
cancel sHttpTid
traverse_ cancel sHttpsTid
io $ Net.close sHttpSock
io $ Net.close sHttpsSock
io $ Net.close sLoopSock
removePortsFile sPortsFile
(void . waitCatch) sLoopTid
(void . waitCatch) sHttpTid