@@ -784,9 +784,11 @@ defmodule SynSupervisor do
784784 reply =
785785 state . scope
786786 |> Distribution . list_children ( )
787- |> Enum . map ( fn % Child { } = c ->
788- { id , _ , _ , _ , type , modules } = c . spec
789- { id , c . pid , type , modules }
787+ |> Enum . flat_map ( fn % Child { } = c ->
788+ case Distribution . spec_for_child ( state . scope , c ) do
789+ { :ok , { id , _ , _ , _ , type , modules } } -> [ { id , c . pid , type , modules } ]
790+ _ -> [ ]
791+ end
790792 end )
791793
792794 { :reply , reply , state }
@@ -832,9 +834,10 @@ defmodule SynSupervisor do
832834 { active , workers , supervisors } =
833835 Enum . reduce ( children , { 0 , 0 , 0 } , fn
834836 % Child { } = c , { active , worker , supervisor } ->
835- case c . spec do
836- { _ , _ , _ , _ , :worker , _ } -> { active + 1 , worker + 1 , supervisor }
837- { _ , _ , _ , _ , :supervisor , _ } -> { active + 1 , worker , supervisor + 1 }
837+ case Distribution . spec_for_child ( state . scope , c ) do
838+ { :ok , { _ , _ , _ , _ , :worker , _ } } -> { active + 1 , worker + 1 , supervisor }
839+ { :ok , { _ , _ , _ , _ , :supervisor , _ } } -> { active + 1 , worker , supervisor + 1 }
840+ _ -> { active , worker , supervisor }
838841 end
839842 end )
840843
@@ -854,10 +857,9 @@ defmodule SynSupervisor do
854857 # try local children anyway
855858 terminate_local_children ( pid_or_child_id , state )
856859
857- { :ok , % Child { node: node , supervisor_pid: supervisor } = c } ->
860+ { :ok , % Child { id: child_id , node: node , supervisor_pid: supervisor } = c } ->
858861 if node == Node . self ( ) do
859- Distribution . untrack_spec ( state . scope , c . spec )
860- terminate_local_children ( c . pid , state )
862+ terminate_local_children_and_untrack_spec ( c . pid , child_id , state )
861863 else
862864 terminate_remote_children ( node , supervisor , c . pid , state )
863865 end
@@ -876,6 +878,17 @@ defmodule SynSupervisor do
876878 end
877879 end
878880
881+ defp terminate_local_children_and_untrack_spec ( pid , child_id , state ) do
882+ case terminate_local_children ( pid , state ) do
883+ { :reply , :ok , next_state } ->
884+ Distribution . untrack_spec ( state . scope , child_id )
885+ { :reply , :ok , next_state }
886+
887+ reply ->
888+ reply
889+ end
890+ end
891+
879892 defp terminate_local_children ( pid , % { children: children } = state ) when is_pid ( pid ) do
880893 case children do
881894 % { ^ pid => info } ->
@@ -1170,13 +1183,23 @@ defmodule SynSupervisor do
11701183
11711184 defp maybe_start_child ( % Child { } = c , assigned_node , _assigned_sup , state ) do
11721185 if assigned_node == Node . self ( ) and c . node != Node . self ( ) do
1173- { _ , _ , state } = start_local_child ( c . spec , state )
1174- state
1186+ find_spec_and_start_local_child ( c . id , state )
11751187 else
11761188 state
11771189 end
11781190 end
11791191
1192+ def find_spec_and_start_local_child ( child_id , state ) do
1193+ case Distribution . find_spec ( state . scope , child_id ) do
1194+ { :ok , child_spec } ->
1195+ { _ , _ , state } = start_local_child ( child_spec , state )
1196+ state
1197+
1198+ _ ->
1199+ state
1200+ end
1201+ end
1202+
11801203 defp monitor_children ( children ) do
11811204 Enum . reduce ( children , { % { } , % { } , % { } } , fn
11821205 { _ , { :restarting , _ } } , acc ->
0 commit comments