Skip to content

Commit fc1c303

Browse files
jvfJosé Valim
authored andcommitted
Fix DynamicSupervisor error report when restarting child (#7377)
Signed-off-by: José Valim <[email protected]>
1 parent 5e1e2e6 commit fc1c303

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/elixir/lib/dynamic_supervisor.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,21 +940,21 @@ defmodule DynamicSupervisor do
940940
end
941941
end
942942

943-
defp report_error(error, reason, pid, child, %{name: name}) do
943+
defp report_error(error, reason, pid, child, %{name: name, extra_arguments: extra}) do
944944
:error_logger.error_report(
945945
:supervisor_report,
946946
supervisor: name,
947947
errorContext: error,
948948
reason: reason,
949-
offender: extract_child(pid, child)
949+
offender: extract_child(pid, child, extra)
950950
)
951951
end
952952

953-
defp extract_child(pid, {mfa, restart, shutdown, type, _modules}) do
953+
defp extract_child(pid, {{m, f, args}, restart, shutdown, type, _modules}, extra) do
954954
[
955955
pid: pid,
956956
id: :undefined,
957-
mfargs: mfa,
957+
mfargs: {m, f, extra ++ args},
958958
restart_type: restart,
959959
shutdown: shutdown,
960960
child_type: type

lib/logger/test/logger/translator_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,26 @@ defmodule Logger.TranslatorTest do
711711
"""
712712
end
713713

714+
test "translates DynamicSupervisor reports extra_arguments in in abnormal shutdown" do
715+
assert capture_log(:info, fn ->
716+
trap = Process.flag(:trap_exit, true)
717+
718+
{:ok, pid} =
719+
DynamicSupervisor.start_link(strategy: :one_for_one, extra_arguments: [:extra])
720+
721+
child = %{id: __MODULE__, start: {__MODULE__, :abnormal2, [:args]}}
722+
{:ok, _pid2} = DynamicSupervisor.start_child(pid, child)
723+
Process.exit(pid, :normal)
724+
receive do: ({:EXIT, ^pid, _} -> :ok)
725+
Process.flag(:trap_exit, trap)
726+
end) =~ ~r"""
727+
\[error\] Child :undefined of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) shutdown abnormally
728+
\*\* \(exit\) :stop
729+
Pid: #PID<\d+\.\d+\.\d+>
730+
Start Call: Logger.TranslatorTest.abnormal2\(:extra, :args\)
731+
"""
732+
end
733+
714734
test "translates :supervisor_bridge progress" do
715735
assert capture_log(:info, fn ->
716736
trap = Process.flag(:trap_exit, true)
@@ -804,6 +824,10 @@ defmodule Logger.TranslatorTest do
804824
:proc_lib.start_link(__MODULE__, :abnormal_init, [])
805825
end
806826

827+
def abnormal2(:extra, :args) do
828+
:proc_lib.start_link(__MODULE__, :abnormal_init, [])
829+
end
830+
807831
def abnormal_init() do
808832
Process.flag(:trap_exit, true)
809833
:proc_lib.init_ack({:ok, self()})

0 commit comments

Comments
 (0)