Skip to content

Commit 815420c

Browse files
jvfJosé Valim
authored andcommitted
Fix DynamicSupervisor handling of extra arguments on child restart (#7371)
Fixes #7369 Signed-off-by: José Valim <[email protected]>
1 parent cba11d6 commit 815420c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/elixir/lib/dynamic_supervisor.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,9 @@ defmodule DynamicSupervisor do
919919

920920
defp restart_child(:one_for_one, current_pid, child, state) do
921921
{{m, f, args} = mfa, restart, shutdown, type, modules} = child
922+
%{extra_arguments: extra} = state
922923

923-
case start_child(m, f, args) do
924+
case start_child(m, f, extra ++ args) do
924925
{:ok, pid, _} ->
925926
state = delete_child(current_pid, state)
926927
{:ok, save_child(pid, mfa, restart, shutdown, type, modules, state)}

lib/elixir/test/elixir/dynamic_supervisor_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ defmodule DynamicSupervisorTest do
353353
assert {:error, :max_children} = DynamicSupervisor.start_child(pid, child)
354354
end
355355

356+
test "restarting a child with extra_args successfully restarts child" do
357+
parent = self()
358+
359+
fun = fn ->
360+
send(parent, :from_child)
361+
:timer.sleep(:infinity)
362+
end
363+
364+
{:ok, sup} = DynamicSupervisor.start_link(strategy: :one_for_one, extra_arguments: [fun])
365+
child = %{id: Task, restart: :transient, start: {Task, :start_link, []}}
366+
367+
assert {:ok, child} = DynamicSupervisor.start_child(sup, child)
368+
assert is_pid(child)
369+
assert_receive :from_child
370+
assert %{active: 1, workers: 1} = DynamicSupervisor.count_children(sup)
371+
assert_kill(child, :oops)
372+
assert_receive :from_child
373+
assert %{workers: 1, active: 1} = DynamicSupervisor.count_children(sup)
374+
end
375+
356376
test "child is restarted when trying again" do
357377
child = current_module_worker([:try_again, self()], restart: :permanent)
358378
{:ok, pid} = DynamicSupervisor.start_link(strategy: :one_for_one, max_restarts: 2)

0 commit comments

Comments
 (0)