cpg registered processes crash VM when killed.
ashneyderman opened this issue · comments
I am looking for process groups lib and was experimenting with cpg. When I register processes via cpg and kill any but he last process in the group the VM crashes. This is with erlang VM 18.1.
I created a little github project to demo the problem:
https://github.com/ashneyderman/cpg_issue.git
The README.md - https://github.com/ashneyderman/cpg_issue/blob/master/README.md - has the shell output and a bit more details on what works and what does not.
Is this a known cpg issue?
Any suggestions on what to do to avoid VM crash?
@ashneyderman This is a misuse of the via syntax. To fix this, use the change:
diff --git a/apps/experiments/src/experiments_sup.erl b/apps/experiments/src/experiments_sup.erl
index 36c17c5..804c4cb 100644
--- a/apps/experiments/src/experiments_sup.erl
+++ b/apps/experiments/src/experiments_sup.erl
@@ -16,7 +16,7 @@ init([]) ->
Procs = [
{truog1, {truog_server,start_link,[zippo1]}, permanent, brutal_kill, worker, [truog_server]},
{truog2, {truog_server,start_link,[zippo2]}, permanent, brutal_kill, worker, [truog_server]},
- {truog3, {truog_server1,start_link,["zippo", 1]}, permanent, brutal_kill, worker, [truog_server1]},
+ {truog3, {truog_server1,start_link,["zippo", 2]}, permanent, brutal_kill, worker, [truog_server1]},
{truog4, {truog_server1,start_link,["zippo", 2]}, permanent, brutal_kill, worker, [truog_server1]}
],
{ok, {{one_for_one, 1, 5}, Procs}}.
The number provided in the via syntax for the start_link is a count not an index. If the number of start_links does not match the count, then the lookup will fail for the OTP source code, thinking it hasn't started the process yet.
Thanks for your help.