Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crash reason handle crash group #720

Merged
merged 12 commits into from
Feb 13, 2024
5 changes: 3 additions & 2 deletions lib/membrane/bin/callback_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ defmodule Membrane.Bin.CallbackContext do
Field `:start_of_stream_received?` is present only in
`c:Membrane.Bin.handle_element_end_of_stream/4`.

Fields `:members` and `:crash_initiator` are present only in
`c:Membrane.Pipeline.handle_crash_group_down/3`.
Fields `:members`, `:crash_initiator` and `reason` and are present only in
`c:Membrane.Bin.handle_crash_group_down/3`.
"""
@type t :: %{
:clock => Membrane.Clock.t(),
Expand All @@ -27,6 +27,7 @@ defmodule Membrane.Bin.CallbackContext do
optional(:pad_options) => map(),
optional(:members) => [Membrane.Child.name()],
optional(:crash_initiator) => Membrane.Child.name(),
optional(:reason) => any(),
DominikWolek marked this conversation as resolved.
Show resolved Hide resolved
optional(:start_of_stream_received?) => boolean()
}
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,27 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
end
end

def handle_crash_group_member_death(child_name, %CrashGroup{} = group, _reason, state) do
def handle_crash_group_member_death(
child_name,
%CrashGroup{} = group,
{:shutdown, :membrane_crash_group_kill},
state
) do
handle_non_normal_member_death(child_name, group, state)
end

def handle_crash_group_member_death(child_name, %CrashGroup{} = group, reason, state) do
state =
update_in(
state,
[:crash_groups, group.name],
&%CrashGroup{&1 | reason: reason}
)

handle_non_normal_member_death(child_name, group, state)
end
DominikWolek marked this conversation as resolved.
Show resolved Hide resolved

defp handle_non_normal_member_death(child_name, group, state) do
state =
if group.detonating? do
state
Expand Down Expand Up @@ -108,7 +128,8 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
context_generator =
&Component.context_from_state(&1,
members: crash_group.members,
crash_initiator: crash_group.crash_initiator
crash_initiator: crash_group.crash_initiator,
reason: crash_group.reason
)

CallbackHandler.exec_and_handle_callback(
Expand Down
7 changes: 5 additions & 2 deletions lib/membrane/core/parent/crash_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Membrane.Core.Parent.CrashGroup do
# * name - name that identifies the group
# * type - responsible for restart policy of members of groups
# * members - list of members of group
# * reason - reason of the crash

use Bunch.Access

Expand All @@ -15,9 +16,11 @@ defmodule Membrane.Core.Parent.CrashGroup do
mode: :temporary,
members: [Membrane.Child.name()],
detonating?: boolean(),
crash_initiator: Membrane.Child.name()
crash_initiator: Membrane.Child.name(),
reason: any()
}

@enforce_keys [:name, :mode]
defstruct @enforce_keys ++ [members: [], detonating?: false, crash_initiator: nil]
defstruct @enforce_keys ++
[members: [], detonating?: false, crash_initiator: nil, reason: :normal]
DominikWolek marked this conversation as resolved.
Show resolved Hide resolved
end
3 changes: 2 additions & 1 deletion lib/membrane/pipeline/callback_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Membrane.Pipeline.CallbackContext do
Field `:start_of_stream_received?` is present only in
`c:Membrane.Pipeline.handle_element_end_of_stream/4`.

Fields `:members` and `:crash_initiator` are present only in
Fields `:members`, `:crash_initiator` and `:reason` are present only in
`c:Membrane.Pipeline.handle_crash_group_down/3`.
"""
@type t :: %{
Expand All @@ -23,6 +23,7 @@ defmodule Membrane.Pipeline.CallbackContext do
optional(:from) => [GenServer.from()],
optional(:members) => [Membrane.Child.name()],
optional(:crash_initiator) => Membrane.Child.name(),
optional(:reason) => any(),
optional(:start_of_stream_received?) => boolean()
}
end
Loading