Skip to content

Commit d21f628

Browse files
committed
Enforce unique child keys on supervisor start/run
1 parent 09c3c85 commit d21f628

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Control/Distributed/Process/Platform/Supervisor.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,10 @@ supInit (strategy', shutdown', specs') = do
963963
`catch` \(e :: SomeException) -> return $ InitStop (show e)
964964
where
965965
initChild :: State -> ChildSpec -> Process State
966-
initChild st ch = tryStartChild ch >>= initialised st ch
966+
initChild st ch =
967+
case (findChild (childKey ch) st) of
968+
Just (ref, _) -> die $ StartFailureDuplicateChild ref
969+
Nothing -> tryStartChild ch >>= initialised st ch
967970

968971
configuredRestartPeriod =
969972
let maxT' = maxT (intensity strategy')

tests/TestSupervisor.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,11 @@ sequentialShutdown result = do
217217
app' <- toChildStart $ runApp sg
218218
let core = (permChild core') { childRegName = Just (LocalName "core")
219219
, childStop = TerminateTimeout (Delay $ within 2 Seconds)
220+
, childKey = "child-1"
220221
}
221222
let app = (permChild app') { childRegName = Just (LocalName "app")
222223
, childStop = TerminateTimeout (Delay $ within 2 Seconds)
224+
, childKey = "child-2"
223225
}
224226

225227
sup <- Supervisor.start restartRight
@@ -1011,7 +1013,8 @@ localChildStartLinking :: TestResult Bool -> Process ()
10111013
localChildStartLinking result = do
10121014
s1 <- toChildStart procExpect
10131015
s2 <- toChildStart procLinkExpect
1014-
pid <- Supervisor.start restartOne ParallelShutdown [tempWorker s1, tempWorker s2]
1016+
pid <- Supervisor.start restartOne ParallelShutdown [ (tempWorker s1) { childKey = "w1" }
1017+
, (tempWorker s2) { childKey = "w2" } ]
10151018
[(r1, _), (r2, _)] <- listChildren pid
10161019
Just p1 <- resolve r1
10171020
Just p2 <- resolve r2

0 commit comments

Comments
 (0)