Skip to content

Commit

Permalink
Remove handle_child_pad_removed implmentation from Zombie modules, ig…
Browse files Browse the repository at this point in the history
…nore :child_pad_removed from terminating children
  • Loading branch information
FelonEkonom committed Feb 16, 2023
1 parent 5f200ed commit 1266f2d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 87 deletions.
33 changes: 2 additions & 31 deletions lib/membrane/core/bin/zombie.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@ defmodule Membrane.Core.Bin.Zombie do

# Overrides all the overridable callbacks to add a debug message that the original
# implementation is not called

grouped_callbacks =
Membrane.Bin.behaviour_info(:callbacks)
|> Enum.group_by(fn callback ->
cond do
Module.overridable?(__MODULE__, callback) -> :overridable
not Module.defines?(__MODULE__, callback) -> :not_implemented
true -> :ignored
end
end)

grouped_callbacks
|> Map.get(:grouped_callbacks, [])
Membrane.Bin.behaviour_info(:callbacks)
|> Enum.filter(&Module.overridable?(__MODULE__, &1))
|> Enum.map(fn {name, arity} ->
args = Enum.map(1..arity//1, &Macro.var(:"arg#{&1}", __MODULE__))

Expand All @@ -34,22 +23,4 @@ defmodule Membrane.Core.Bin.Zombie do
super(unquote_splicing(args))
end
end)

grouped_callbacks
|> Map.get(:not_implemented)
|> Enum.map(fn {name, arity} ->
args = Enum.map(1..arity//1, &Macro.var(:"arg#{&1}", __MODULE__))

@impl true
def unquote(name)(unquote_splicing(args)) do
Membrane.Logger.debug(
"Not calling the #{unquote(name)} callback with the following arguments:
#{Enum.map_join(unquote(args), ", ", &inspect/1)}
because the bin is in the zombie mode"
)

state = List.last([unquote_splicing(args)])
{[], state}
end
end)
end
26 changes: 16 additions & 10 deletions lib/membrane/core/parent/child_life_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,24 @@ defmodule Membrane.Core.Parent.ChildLifeController do
def handle_child_pad_removed(child, pad, state) do
Membrane.Logger.debug_verbose("Child #{inspect(child)} removed pad #{inspect(pad)}")

Parent.ChildrenModel.assert_child_exists!(state, child)
child_terminating? = Parent.ChildrenModel.get_child_data!(state, child).terminating?

state =
CallbackHandler.exec_and_handle_callback(
:handle_child_pad_removed,
Component.action_handler(state),
%{context: &Component.context_from_state/1},
[child, pad],
state
)
unless child_terminating? do
Parent.ChildrenModel.assert_child_exists!(state, child)

state =
CallbackHandler.exec_and_handle_callback(
:handle_child_pad_removed,
Component.action_handler(state),
%{context: &Component.context_from_state/1},
[child, pad],
state
)

LinkUtils.handle_child_pad_removed(child, pad, state)
LinkUtils.handle_child_pad_removed(child, pad, state)
else
state
end
end

@doc """
Expand Down
28 changes: 13 additions & 15 deletions lib/membrane/core/parent/child_life_controller/link_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,21 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkUtils do

@spec handle_child_pad_removed(Child.name(), Pad.ref(), Parent.state()) :: Parent.state()
def handle_child_pad_removed(child, pad, state) do
with {:ok, link} <- get_link(state.links, child, pad) do
state =
opposite_endpoint(link, child)
|> case do
%Endpoint{child: {Membrane.Bin, :itself}} = bin_endpoint ->
PadController.remove_pad!(bin_endpoint.pad_ref, state)
{:ok, link} = get_link(state.links, child, pad)

%Endpoint{} = endpoint ->
Message.send(endpoint.pid, :handle_unlink, endpoint.pad_ref)
state
end
state =
opposite_endpoint(link, child)
|> case do
%Endpoint{child: {Membrane.Bin, :itself}} = bin_endpoint ->
PadController.remove_pad!(bin_endpoint.pad_ref, state)

ChildLifeController.remove_link_from_specs(link.id, state)
|> Map.update!(:links, &Map.delete(&1, link.id))
else
{:error, :not_found} -> state
end
%Endpoint{} = endpoint ->
Message.send(endpoint.pid, :handle_unlink, endpoint.pad_ref)
state
end

ChildLifeController.remove_link_from_specs(link.id, state)
|> Map.update!(:links, &Map.delete(&1, link.id))
end

@spec remove_link(Child.name(), Pad.ref(), Parent.state()) :: Parent.state()
Expand Down
33 changes: 2 additions & 31 deletions lib/membrane/core/pipeline/zombie.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ defmodule Membrane.Core.Pipeline.Zombie do

# Overrides all the overridable callbacks to add a debug message that the original
# implementation is not called

grouped_callbacks =
Membrane.Pipeline.behaviour_info(:callbacks)
|> Enum.group_by(fn callback ->
cond do
Module.overridable?(__MODULE__, callback) -> :overridable
not Module.defines?(__MODULE__, callback) -> :not_implemented
true -> :ignored
end
end)

grouped_callbacks
|> Map.get(:grouped_callbacks, [])
Membrane.Bin.behaviour_info(:callbacks)
|> Enum.filter(&Module.overridable?(__MODULE__, &1))
|> Enum.map(fn {name, arity} ->
args = Enum.map(1..arity//1, &Macro.var(:"arg#{&1}", __MODULE__))

Expand All @@ -35,22 +24,4 @@ defmodule Membrane.Core.Pipeline.Zombie do
super(unquote_splicing(args))
end
end)

grouped_callbacks
|> Map.get(:not_implemented)
|> Enum.map(fn {name, arity} ->
args = Enum.map(1..arity//1, &Macro.var(:"arg#{&1}", __MODULE__))

@impl true
def unquote(name)(unquote_splicing(args)) do
Membrane.Logger.debug(
"Not calling the #{unquote(name)} callback with the following arguments:
#{Enum.map_join(unquote(args), ", ", &inspect/1)}
because the pipeline is in the zombie mode"
)

state = List.last([unquote_splicing(args)])
{[], state}
end
end)
end

0 comments on commit 1266f2d

Please sign in to comment.