Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Work-around for #546
Browse files Browse the repository at this point in the history
If the `reason` passed to `__lumen_builtin_error` is a 2-tuple of `{Class, Reason}` where `Class` is `error` or `exit`, exit the process with just `Reason`.
  • Loading branch information
KronicDeth committed Aug 24, 2020
1 parent aad772c commit d2283c9
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ start() ->
end
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ParentMonitorReference, process, _, Reason} ->
display({parent, exited, Reason});
10 ->
display({parent, alive, is_process_alive(ParentPid)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ start() ->
ChildMonitorReference = monitor(process, ChildPid),
shutdown(ParentPid),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
display({parent, exited, Reason1})
after 10 ->
display({parent, alive, is_process_alive(ParentPid)})
end,
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
display({child, exited, Reason2})
after 10 ->
display({child, alive, is_process_alive(ChildPid)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ test_stdout!(
);
test_stdout!(
with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal,
"{trap_exit, true}\n{parent, alive, true}\n{child, alive, false}\n"
"{trap_exit, true}\n{parent, alive, true}\n{child, exited, normal}\n"
);
test_stdout!(
with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal,
"{trap_exit, true}\n{parent, sees, child, exit, due, to, abnormal}\n{parent, alive, true}\n{child, exited, abnormal}\n"
"{trap_exit, true}\n{parent, alive, true}\n{child, exited, abnormal}\n{parent, sees, child, alive, false}\n"
);
test_stdout!(
with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ end),
ChildMonitorReference = monitor(process, ChildPid),
shutdown(ParentPid),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
display({parent, exited, Reason1})
after 10 ->
display({parent, alive, is_process_alive(ParentPid)})
end,
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
display({child, exited, Reason2})
after 10 ->
display({child, alive, is_process_alive(ChildPid)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ start() ->
ChildMonitorReference = monitor(process, ChildPid),
shutdown_child(ParentPid),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
display({parent, exited, Reason1})
after 10 ->
display({parent, alive, is_process_alive(ParentPid)})
end,
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
display({child, exited, Reason2})
after 10 ->
display({child, alive, is_process_alive(ChildPid)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ start() ->
ChildMonitorReference = monitor(process, ChildPid),
shutdown_child(ParentPid),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
display({parent, exited, Reason1})
after 10 ->
display({parent, alive, is_process_alive(ParentPid)})
end,
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
display({child, exited, Reason2})
after 10 ->
display({child, alive, is_process_alive(ChildPid)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ start() ->
receive
{'DOWN', MonitorRef, process, _, Info} ->
case Info of
{error, {Reason, _Stacktrace}} -> display(Reason);
%% FIXME https://github.com/lumen/lumen/issues/548
{Reason, FunArgs} -> display(Reason);
Other -> display(Other)
end
after 20 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ start() ->
ok
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ParentMonitorReference, process, _, Reason} ->
display({parent, Reason})
after
100 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ start() ->
ok
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ParentMonitorReference, process, _, Reason} ->
display({parent, Reason})
after
100 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ start() ->
ok
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ParentMonitorReference, process, _, {error, Info}} ->
{'DOWN', ParentMonitorReference, process, _, Info} ->
case Info of
{badarity = Reason, FunArgs} ->
display({parent, Reason});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ start() ->
exit(Environment)
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ChildMonitorReference, process, _, Reason} ->
display({child, exited, Reason})
after 10 ->
display(timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ start() ->
exit(Environment)
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ChildMonitorReference, process, _, Reason} ->
display({child, exited, Reason})
after 10 ->
display(timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ start() ->
exit(abnormal)
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
{'DOWN', ChildMonitorReference, process, _, Reason} ->
display({child, exited, Reason})
after 10 ->
display(timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ start() ->
display(A)
end),
receive
%% FIXME https://github.com/lumen/lumen/issues/546
{'DOWN', ChildMonitorReference, process, _, {error, {Reason, Details}}} ->
{'DOWN', ChildMonitorReference, process, _, {Reason, Details}} ->
display({child, exited, Reason})
after 10 ->
display(timeout)
Expand Down
30 changes: 29 additions & 1 deletion runtimes/minimal/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,40 @@ pub unsafe extern "C" fn process_exit(reason: Term) {
.as_any()
.downcast_ref::<Scheduler>()
.unwrap();
// FIXME https://github.com/lumen/lumen/issues/546
let exit_reason = work_around546(reason);

scheduler
.current
.exit(reason, anyhow!("process exit").into());
.exit(exit_reason, anyhow!("process exit").into());
scheduler.process_yield();
}

// Work-around: Unwrap `{class, reason}`, but it means that processes can't exit with a reason
// that looks like `{class, reason}.
fn work_around546(reason: Term) -> Term {
match reason.decode().unwrap() {
TypedTerm::Tuple(boxed_tuple) => {
let elements = boxed_tuple.elements();

if elements.len() == 2 {
let class = elements[0];

match class.decode().unwrap() {
TypedTerm::Atom(class_atom) => match class_atom.name() {
"error" | "exit" => elements[1],
_ => reason,
},
_ => reason,
}
} else {
reason
}
}
_ => reason,
}
}

#[naked]
#[inline(never)]
#[cfg(all(unix, target_arch = "x86_64"))]
Expand Down

0 comments on commit d2283c9

Please sign in to comment.