You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/useful_concepts/crash_groups.md
+9-39Lines changed: 9 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,18 +33,7 @@ end
33
33
When an element belonging to a crash group crashes:
34
34
1. All other elements in the same crash group are terminated by the pipeline.
35
35
2. The pipeline's `handle_crash_group_down/3` callback is invoked.
36
-
3. You can decide whether to restart the group, ignore the failure, or terminate the pipeline.
37
-
38
-
## Handling Failures
39
-
40
-
To react to a crash group failure, implement the `handle_crash_group_down/3` callback:
41
-
42
-
```elixir
43
-
@impltrue
44
-
defhandle_crash_group_down(crash_group_id, context, state) do
45
-
# Logic to restart the group or handle the error
46
-
end
47
-
```
36
+
3. You can decide whether to restart the group, ignore the failure, or handle this situation any other way.
48
37
49
38
## Flow of all callbacks reated to a crash within a crash group.
50
39
@@ -64,7 +53,7 @@ end
64
53
`context` passed to this callback will contain few extra fileds:
65
54
*`context.exit_reason` - in this case equals `{%RuntimeError{message: "internal error"}, _stacktrace}`.
66
55
*`context.group_name` - because `:filter` was spawned inside `:my_group` group, it equals `:my_group`. If a child is spawned beyond any crash group and is terminated gracefully, value of this field is `nil`.
67
-
*`context.crash_initiator` - the same as child's reference, that is `:filter`.
56
+
*`context.crash_initiator` - the same as child's reference, which is `:filter`.
68
57
69
58
`:filter` won't be present in `context.children`, so you could respawn it here, however it is suggested to do it in `handle_crash_group_down/3` later.
70
59
@@ -82,10 +71,9 @@ end
82
71
```
83
72
84
73
callback. Each time, `context` will contain following extra fields:
85
-
*`context.exit_reason` - for these terminations, equals `{:shutdown, :membrane_crash_group_kill}`.
Note, that `context.children` map always contains only children that are still alive. E.g. if `:source` is terminated first, `hanlde_child_terminated(:source, context, state)` will contain only `:sink` in `context.children` map and for `hanlde_child_terminated(:sink, context, state)``context.children` will be empty.
91
79
@@ -102,27 +90,9 @@ def handle_crash_group_down(:my_group, context, state) do
102
90
end
103
91
```
104
92
105
-
`context` passed as a third argument to `handle_crash_group_down/3` callback contains 3 additional fields, that usually don't occur in contexts of other callbacks:
106
-
-`context.crash_initiator` - name or reference of the child that crashed first and caused the crash group to explode.
107
-
-`context.crash_reason` - the reason with which `context.crash_initiator` crashed.
108
-
-`context.members` - names/references of all children that were in the crash group.
109
-
TODO: continue
110
-
111
-
112
-
Question marks:
113
-
- is crash group initiator in context.members?
114
-
- what is the order in of:
115
-
*`handle_crash_group_down`
116
-
*`handle_child_terminated`
117
-
* removing children from `context.children`, so that it becames possible to respawn new children with the same names?
118
-
- what is the relation between `handle_child_pad_removed` and `handle_crash_group_down`?
119
-
120
-
121
-
122
-
## Use Cases
123
-
## tutaj poniej mamy AI BS, no chodzi o to ze jak mamy element co sie wydupca, to nie chcemy zeby wszystko poszlo w piach, wiec wrzucamy go (i byc moze cos co i tak bysmy chcieli razem z nim zrestartowac) do crash groupy
124
-
125
-
-**Atomic logical units:** When a group of elements (like an encoder and its associated parser) cannot function independently.
126
-
-**Resource Cleanup:** Ensuring that if a consumer crashes, the producer is also stopped to prevent buffered data from leaking memory.
127
-
-**Error Recovery:** Grouping elements that require a specific initialization sequence that must be repeated upon failure.
93
+
`context` passed as a third argument to `handle_crash_group_down/3` callback contains 3 additional fields:
94
+
-`context.crash_initiator` - name or reference of the child that crashed first and caused the crash group to explode. In this case, equals `:filter`
95
+
-`context.crash_reason` - the reason with which `context.crash_initiator` crashed. In this case, equals `{%RuntimeError{message: "internal error"}, _stacktrace}`.
96
+
-`context.members` - names/references of all children that were in the crash group. In this case, equals `[:source, :filter, :sink]`
128
97
98
+
When `handle_crash_group_down/3` is executed, you can be sure that all group members are already terminated. It is a suggested place, to e.g. respawn crash group. Doing so in `handle_child_terminated/3` might lead to some problems, because the order of group members termination might vary. Moreover, if pipeline or bin terminates its children gracefully, using `t:Membrane.Pipline.Action.remove_children()` action, `handle_child_terminated/3` callback will be also executed with `context.exit_reason` set to `normal`.
0 commit comments