@@ -139,7 +139,8 @@ defmodule Membrane.Core.SubprocessSupervisor do
139139 name: { __MODULE__ , name } ,
140140 type: :supervisor ,
141141 child_pid: child_pid ,
142- role: :subprocess_supervisor
142+ role: :subprocess_supervisor ,
143+ pending_child_death: nil
143144 } )
144145
145146 { :reply , { :ok , child_pid } , state }
@@ -221,7 +222,7 @@ defmodule Membrane.Core.SubprocessSupervisor do
221222
222223 defp do_handle_info ( { :EXIT , pid , reason } , state ) do
223224 { data , state } = pop_in ( state , [ :children , pid ] )
224- handle_exit ( data , reason , state )
225+ state = handle_exit ( data , reason , state )
225226
226227 case state do
227228 % { parent_process: :exit_requested , children: children } when children == % { } ->
@@ -245,27 +246,33 @@ defmodule Membrane.Core.SubprocessSupervisor do
245246 end
246247
247248 defp handle_exit ( % { role: :subprocess_supervisor } = data , reason , state ) do
248- case Map . fetch ( state . children , data . child_pid ) do
249+ with :error <- Map . fetch ( state . children , data . child_pid ) ,
250+ % { pending_child_death: { child_name , death_reason } } <- data do
251+ Message . send ( state . parent_component , :child_death , [ child_name , death_reason ] )
252+ else
249253 { :ok , child_data } ->
250254 raise "Subprocess supervisor failure #{ inspect ( child_data . name ) } , reason: #{ inspect ( reason ) } "
251255
252- :error ->
256+ _no_pending_death ->
253257 :ok
254258 end
259+
260+ state
255261 end
256262
257263 defp handle_exit ( % { role: :component } = data , reason , state ) do
258264 Process . exit ( data . supervisor_pid , :shutdown )
259- Message . send ( state . parent_component , :child_death , [ data . name , reason ] )
265+
266+ put_in ( state . children [ data . supervisor_pid ] . pending_child_death , { data . name , reason } )
260267 end
261268
262- defp handle_exit ( % { role: :utility } , _reason , _state ) do
263- :ok
269+ defp handle_exit ( % { role: :utility } , _reason , state ) do
270+ state
264271 end
265272
266273 # Clause handling the case when child start function returns error
267274 # and we don't know its PID, but we still receive exit signal from it.
268- defp handle_exit ( nil , _reason , _state ) do
269- :ok
275+ defp handle_exit ( nil , _reason , state ) do
276+ state
270277 end
271278end
0 commit comments