Here is part of the source code of application master, which is the module managing an erlang application.
348 loop_it(Parent, Child, Mod, AppState) ->
349 receive
350 {Parent, get_child} ->
351 Parent ! {self(), Child, Mod},
352 loop_it(Parent, Child, Mod, AppState);
353 {Parent, terminate} ->
354 NewAppState = prep_stop(Mod, AppState),
355 exit(Child, shutdown),
356 receive
357 {'EXIT', Child, _} -> ok
358 end,
359 catch Mod:stop(NewAppState),
360 exit(normal);
361 {'EXIT', Parent, Reason} ->
362 NewAppState = prep_stop(Mod, AppState),
363 exit(Child, Reason),
364 receive
365 {'EXIT', Child, Reason2} ->
366 exit(Reason2)
367 end,
368 catch Mod:stop(NewAppState);
369 {'EXIT', Child, Reason} -> % forward *all* exit reasons (inc. normal)
370 NewAppState = prep_stop(Mod, AppState),
371 catch Mod:stop(NewAppState),
372 exit(Reason);
373 _ ->
374 loop_it(Parent, Child, Mod, AppState)
375 end.
My question is:
Why is the behaviour of application master different when it receives {Parent, terminate} and {'EXIT', Parent, Reason}?
What does the code in line 368 mean? The application master must have exited before in line 366.