Skip to content

Commit

Permalink
Supervisor: old child specs remained in CRDT after process handoff
Browse files Browse the repository at this point in the history
When an existing child spec was added to the CRDT during process
handoff, the old child spec is never removed from the CRDT, creating
lingering child specs which results in "zombie" processes spawning
when a new supervisor is started.
  • Loading branch information
arjan authored and derekkraan committed Feb 12, 2024
1 parent 77b9593 commit 9a71dd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/horde/dynamic_supervisor_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ defmodule Horde.DynamicSupervisorImpl do

case current_member do
%{status: :dead} ->
DeltaCrdt.delete(crdt_name(state.name), {:process, child_spec.id}, :infinity)
{_response, state} = add_child(randomize_child_id(child_spec), state)

state
Expand Down
12 changes: 12 additions & 0 deletions test/dynamic_supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,18 @@ defmodule DynamicSupervisorTest do

Process.sleep(5000)
assert_receive {:starting, 5000}, 100

# we have 2 supervised processes
processes = :sys.get_state(:horde_2_graceful).processes_by_id
assert Horde.TableUtils.size_of(processes) == 2

# peek into the remaining supervisor, getting the supervised pids
pids =
:sys.get_state(:horde_2_graceful).processes_by_id
|> :ets.tab2list()
|> Enum.map(&(elem(&1, 1) |> elem(2)))

assert Enum.all?(pids, &Process.alive?/1)
end
end

Expand Down

0 comments on commit 9a71dd1

Please sign in to comment.