firefly icon indicating copy to clipboard operation
firefly copied to clipboard

Parent process for spawn_link/1 exits with {exit, ChildReason} instead of just ChildReason when monitored

Open KronicDeth opened this issue 5 years ago • 0 comments

init.erl

-module(init).
-export([start/0]).
-import(erlang, [display/1]).
-import(lumen, [log_exit/1]).

start() ->
  lumen:log_exit(false),
  {ParentPid, ParentMonitorReference} = spawn_monitor(fun () ->
    ChildPid = spawn_link(fun () ->
      wait_to_shutdown(),
      exit(shutdown)
    end),
    ChildMonitorRef = monitor(process, ChildPid),
    shutdown(ChildPid),
    receive
      {'DOWN', ChildMonitorRef, process, _, Info} ->
        display({child, exited, Info})
    after
      10 ->
        display({child, alive, is_process_alive(ChildPid)})
    end,
    ok
  end),
  receive
    {'DOWN', ParentMonitorReference, process, _, Info} ->
      display({parent, Info})
  after
    100 ->
      display({parent, alive, is_process_alive(ParentPid)})
  end,
  ok.

shutdown(Pid) ->
  Pid ! shutdown.

wait_to_shutdown() ->
  receive
    shutdown -> ok
  end.

Actual Output

{parent, {exit, shutdown}}

Expected Output

{parent, shutdown}

KronicDeth avatar Aug 23 '20 21:08 KronicDeth