Verified Commit 032e5ddb authored by Camil Staps's avatar Camil Staps 🚀

Automatically restart after 1h to preven cold boot issues (#113)

parent 41c5dbd7
......@@ -80,7 +80,8 @@ Start w
{ handler = handle db
, logger = Just log
, port = toInt port
, keepalive_timeout = Just 5000
, connect_timeout = Just 3600000 // 1h
, keepalive_timeout = Just 5000 // 5s
} w
where
help :: *World -> *World
......
......@@ -16,6 +16,7 @@ from TCPIP import ::IPAddress, ::Port
= { handler :: !a *World -> *(!b, !t, !*World)
, logger :: !Maybe (Logger a b s t)
, port :: !Int
, connect_timeout :: !Maybe Int
, keepalive_timeout :: !Maybe Int
}
......
......@@ -12,35 +12,40 @@ serve server w
# (ok, mbListener, w) = openTCP_Listener server.port w
| not ok = abort ("Couldn't open port " +++ toString server.port +++ "\n")
# listener = fromJust mbListener
# log = if (isNothing server.logger) zero (fromJust server.logger)
# (_,w) = signal 17 1 w // SIGCHLD, SIG_IGN: no notification if child ps dies
# (listener, w) = loop server.handler log listener w
# (listener, w) = loop listener w
= closeRChannel listener w
where
loop :: (a *World -> *(b,t,*World)) (Logger a b s t) TCP_Listener *World
-> (TCP_Listener, *World) | fromString a & toString b
loop f log li w
#! ((ip,dupChan),li,w) = receive li w
# (pid,w) = fork w
| pid < 0 = abort "fork failed\n"
| pid > 0 = loop f log li w // Parent: handle new requests
#! (st,w) = log (Connected ip) Nothing w
= handle f log st dupChan w // Child: handle current request
logger = if (isNothing server.logger) zero (fromJust server.logger)
handle :: !(a *World-> (b,t,*World)) !(Logger a b s t) !(Maybe s) !TCP_DuplexChannel
!*World -> *(!TCP_Listener, !*World) | fromString a & toString b
handle f log st dupChannel=:{rChannel,sChannel} w
# (tRep,msg,rChannel,w) = receive_MT server.keepalive_timeout rChannel w
loop :: TCP_Listener *World -> (TCP_Listener, *World)
loop li w
#! (tRep,conn,li,w) = receive_MT server.connect_timeout li w
| tRep <> TR_Success
# (st,w) = log Disconnected st w
# w = closeChannel sChannel (closeRChannel rChannel w)
= (li,w)
#! (ip,dupChan) = fromJust conn
#! (pid,w) = fork w
| pid < 0
= abort "fork failed\n"
| pid > 0 // Parent: handle new requests
= loop li w
| pid == 0 // Child: handle current request
#! (st,w) = logger (Connected ip) Nothing w
= handle st dupChan w
//handle :: !(Maybe s) !TCP_DuplexChannel !*World -> *(!TCP_Listener, !*World)
handle st dupChannel=:{rChannel,sChannel} w
#! (tRep,msg,rChannel,w) = receive_MT server.keepalive_timeout rChannel w
| tRep <> TR_Success
#! (st,w) = logger Disconnected st w
#! w = closeChannel sChannel (closeRChannel rChannel w)
= exit 0 w
# msg = fromString (toString (fromJust msg))
# (st, w) = log (Received msg) st w
# (resp, hidden, w) = f msg w
# (sChannel, w) = send (toByteSeq (toString resp)) sChannel w
# (st, w) = log (Sent resp hidden) st w
= handle f log st {dupChannel & rChannel=rChannel, sChannel=sChannel} w
#! msg = fromString (toString (fromJust msg))
#! (st, w) = logger (Received msg) st w
#! (resp, hidden, w) = server.handler msg w
#! (sChannel, w) = send (toByteSeq (toString resp)) sChannel w
#! (st, w) = logger (Sent resp hidden) st w
= handle st {dupChannel & rChannel=rChannel, sChannel=sChannel} w
signal :: !Int !Int !*World -> *(!Int, !*World)
signal signum handler w = code {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment