Skip to content

Commit 240d20e

Browse files
authored
Reshape put_in/update_in calls in crashgroups (#811)
* Reshape put_in/update_in calls in crashgroups * Add debug log about error in handling actions * Fix test * Add comment
1 parent 3f9e0eb commit 240d20e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/membrane/core/callback_handler.ex

+21
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ defmodule Membrane.Core.CallbackHandler do
185185
Error handling actions returned by callback #{inspect(state.module)}.#{callback}
186186
""")
187187

188+
log_debug_orginal_error(actions, e, __STACKTRACE__)
189+
188190
reraise e, __STACKTRACE__
189191
end
190192

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

203+
log_debug_orginal_error(action, e, __STACKTRACE__)
204+
201205
reraise e, __STACKTRACE__
202206
end
203207
end)
204208

205209
handler_module.handle_end_of_actions(state)
206210
end
211+
212+
# We log it, because sometimes, for some reason, crashing process doesn't cause
213+
# printing error logs on stderr, so this debug log allows us to get some info
214+
# about what happened in case of process crash
215+
defp log_debug_orginal_error(action_or_actions, error, stacktrace) do
216+
action_or_actions =
217+
if(is_list(action_or_actions), do: "actions ", else: "action ") <>
218+
inspect(action_or_actions, limit: :infinity)
219+
220+
Membrane.Logger.debug("""
221+
Error while handling #{action_or_actions}
222+
223+
Orginal error:
224+
#{inspect(error, pretty: true, limit: :infinity)}
225+
#{Exception.format_stacktrace(stacktrace)}
226+
""")
227+
end
207228
end

lib/membrane/core/parent/child_life_controller/crash_group_utils.ex

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
1616
def add_crash_group(group_name, mode, children, state)
1717
when not is_map_key(state.crash_groups, group_name) do
1818
put_in(
19-
state,
20-
[:crash_groups, group_name],
19+
state.crash_groups[group_name],
2120
%CrashGroup{
2221
name: group_name,
2322
mode: mode,
@@ -28,7 +27,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
2827

2928
@spec extend_crash_group(Child.group(), [Child.name()], Parent.state()) :: Parent.state()
3029
def extend_crash_group(group_name, children, state) do
31-
update_in(state, [:crash_groups, group_name, :members], &(children ++ &1))
30+
update_in(state.crash_groups[group_name].members, &(children ++ &1))
3231
end
3332

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

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

8584
update_in(
86-
state,
87-
[:crash_groups, group.name],
85+
state.crash_groups[group.name],
8886
&%CrashGroup{
8987
&1
9088
| detonating?: true,
@@ -96,15 +94,15 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupUtils do
9694

9795
defp cleanup_crash_group(group_name, state) do
9896
state = exec_handle_crash_group_down(group_name, state)
99-
{_group, state} = pop_in(state, [:crash_groups, group_name])
97+
{_group, state} = pop_in(state.crash_groups[group_name])
10098
state
10199
end
102100

103101
defp exec_handle_crash_group_down(
104102
group_name,
105103
state
106104
) do
107-
crash_group = get_in(state, [:crash_groups, group_name])
105+
crash_group = state.crash_groups[group_name]
108106

109107
context_generator =
110108
&Component.context_from_state(&1,

0 commit comments

Comments
 (0)