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

Reshape put_in/update_in calls in crashgroups #811

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/membrane/core/callback_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ defmodule Membrane.Core.CallbackHandler do
Error handling actions returned by callback #{inspect(state.module)}.#{callback}
""")

log_debug_orginal_error(actions, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end

Expand All @@ -198,10 +200,29 @@ defmodule Membrane.Core.CallbackHandler do
Error handling action #{inspect(action)} returned by callback #{inspect(state.module)}.#{callback}
""")

log_debug_orginal_error(action, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end
end)

handler_module.handle_end_of_actions(state)
end

# We log it, because sometimes, for some reason, crashing process doesn't cause
# printing error logs on stderr, so this debug log allows us to get some info
# about what happened in case of process crash
defp log_debug_orginal_error(action_or_actions, error, stacktrace) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment why we do that

action_or_actions =
if(is_list(action_or_actions), do: "actions ", else: "action ") <>
inspect(action_or_actions, limit: :infinity)

Membrane.Logger.debug("""
Error while handling #{action_or_actions}

Orginal error:
#{inspect(error, pretty: true, limit: :infinity)}
#{Exception.format_stacktrace(stacktrace)}
""")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
def add_crash_group(group_name, mode, children, state)
when not is_map_key(state.crash_groups, group_name) do
put_in(
state,
[:crash_groups, group_name],
state.crash_groups[group_name],
%CrashGroup{
name: group_name,
mode: mode,
Expand All @@ -28,7 +27,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do

@spec extend_crash_group(Child.group(), [Child.name()], Parent.state()) :: Parent.state()
def extend_crash_group(group_name, children, state) do
update_in(state, [:crash_groups, group_name, :members], &(children ++ &1))
update_in(state.crash_groups[group_name].members, &(children ++ &1))
end

@spec get_child_crash_group(Child.name(), Parent.state()) :: {:ok, CrashGroup.t()} | :error
Expand All @@ -44,7 +43,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
# and we will not want to have it in :crash_group_members in the callback context in handle_crash_group_down/3,
# so this child is removed from :members in crash group struct
members = List.delete(group.members, child_name)
state = put_in(state, [:crash_groups, group.name, :members], members)
state = put_in(state.crash_groups[group.name].members, members)

if group.detonating? and Enum.all?(members, &(not Map.has_key?(state.children, &1))) do
cleanup_crash_group(group.name, state)
Expand Down Expand Up @@ -83,8 +82,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
end)

update_in(
state,
[:crash_groups, group.name],
state.crash_groups[group.name],
&%CrashGroup{
&1
| detonating?: true,
Expand All @@ -96,15 +94,15 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do

defp cleanup_crash_group(group_name, state) do
state = exec_handle_crash_group_down(group_name, state)
{_group, state} = pop_in(state, [:crash_groups, group_name])
{_group, state} = pop_in(state.crash_groups[group_name])
state
end

defp exec_handle_crash_group_down(
group_name,
state
) do
crash_group = get_in(state, [:crash_groups, group_name])
crash_group = state.crash_groups[group_name]

context_generator =
&Component.context_from_state(&1,
Expand Down