sasa1977 / elixir-in-action

Code samples for Elixir in Action book
947 stars 199 forks source link

[ch09] - ProcessRegistry restarts crash the App #23

Open ajayvigneshk opened 2 years ago

ajayvigneshk commented 2 years ago

In Chapter 09, section 9.1, the following code on iex

Todo.System.start_link
Process.exit(Process.whereis(Todo.ProcessRegistry),:kill)

causes the Supervisor to crash(after trying to restart the children). Trying to inspect the result of Registry.start_link, it shows

{:error,
 {:shutdown,
  {:failed_to_start_child, Todo.ProcessRegistry.PIDPartition0,
   {:already_started, #PID<0.183.0>}}}}

Am guessing that this happens because the supervisor is starting ProcessRegistry in succession before the actual Registry is shutdown and keeps erroring 3 times, ending up in shutdown. Is that correct? How to handle this scenario gracefully?