Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process leak on Supervisor with StarterProcess (DPP-84) #77

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions src/Control/Distributed/Process/Platform/Supervisor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ processDefinition =
-- adding, removing and (optionally) starting new child specs
, handleCall handleTerminateChild
-- , handleCast handleDelayedRestart
, Restricted.handleCall handleDeleteChild
, handleCall handleDeleteChild
, Restricted.handleCallIf (input (\(AddChild immediate _) -> not immediate))
handleAddChild
, handleCall handleStartNewChild
Expand Down Expand Up @@ -1096,26 +1096,38 @@ handleIgnore (IgnoreChildReq pid) = do
resetChildIgnored key state =
maybe state id $ updateChild key (setChildStopped True) state

handleDeleteChild :: DeleteChild
-> RestrictedProcess State (Result DeleteChildResult)
handleDeleteChild (DeleteChild k) = getState >>= handleDelete k
handleDeleteChild :: State
-> DeleteChild
-> Process (ProcessReply DeleteChildResult State)
handleDeleteChild st0 (DeleteChild k) = handleDelete k st0
where
handleDelete :: ChildKey
-> State
-> RestrictedProcess State (Result DeleteChildResult)
handleDelete key state =
let (prefix, suffix) = Seq.breakl ((== key) . childKey . snd) $ state ^. specs
-> Process (ProcessReply DeleteChildResult State)
handleDelete key st =
let (prefix, suffix) = Seq.breakl ((== key) . childKey . snd) $ st ^. specs
in case (Seq.viewl suffix) of
EmptyL -> Restricted.reply ChildNotFound
child :< remaining -> tryDeleteChild child prefix remaining state
EmptyL -> reply ChildNotFound st
child :< remaining -> tryDeleteChild child prefix remaining st

tryDeleteChild (ref, spec) pfx sfx st
| ref == ChildStopped = do
putState $ ( (specs ^= pfx >< sfx)
$ bumpStats Specified (childType spec) decrement st
)
Restricted.reply ChildDeleted
| otherwise = Restricted.reply $ ChildNotStopped ref
removeRestarterProcess spec
let st' = ( (specs ^= pfx >< sfx)
$ bumpStats Specified (childType spec) decrement st
)
reply ChildDeleted st'
| otherwise = reply (ChildNotStopped ref) st

removeRestarterProcess :: ChildSpec -> Process ()
removeRestarterProcess spec = case childStart spec of
(StarterProcess restarterPid) ->
-- NOTE: the childProcess is not linked to
-- the restarterProcess, therefore this is safe
-- to do.
kill restarterPid "TerminatedBySupervisor"
_ -> return ()


handleStartChild :: State
-> StartChildReq
Expand Down