Coder Social home page Coder Social logo

Comments (8)

gmdorf avatar gmdorf commented on August 25, 2024

@derekkraan I am sure that I am doing something wrong here, but this issue/my mistake is my blocking my team in production.

from horde.

gmdorf avatar gmdorf commented on August 25, 2024

This could be related maybe? #219

from horde.

derekkraan avatar derekkraan commented on August 25, 2024

Hi, can you put your failing test in a test in a branch and link it here?

from horde.

gmdorf avatar gmdorf commented on August 25, 2024

I will put it in a branch within a second.

It seems to be an issue of names vs pids. If change the test to never refer to the pid for the DynamicSupervisor or Horde.DynamicSupervisor, but instead to the name, it passes.

defmodule BasicGenServer do
  use GenServer

  def start_link(arg) do
    GenServer.start_link(__MODULE__, arg)
  end

  @impl true
  def init(init_arg) do
    {:ok, init_arg}
  end

  @impl true
  def handle_info(:stop_normal, state) do
    {:stop, :normal, state}
  end
end

{:ok, _sup} = DynamicSupervisor.start_link([strategy: :one_for_one, name: TestSup, automatic_shutdown: :never])

{:ok, child1} = DynamicSupervisor.start_child(TestSup, %{id: :child1, start: {BasicGenServer, :start_link, [0]}})
{:ok, child2} = DynamicSupervisor.start_child(TestSup, %{id: :child2, start: {BasicGenServer, :start_link, [0]}})
{:ok, child3} = DynamicSupervisor.start_child(TestSup, %{id: :child3, start: {BasicGenServer, :start_link, [0]}})

Process.exit(child1, :kill)
IO.puts("Sent :stop_normal message to child of TestSup")
children = DynamicSupervisor.which_children(TestSup)

if Enum.count(children, fn {_id, _pid, _type, mod} -> [BasicGenServer] == mod end) != 3 do
  raise "Not 3 BasicGenServers for TestSup"
else
  IO.inspect(children)
  IO.puts("3 children for TestSup!")
end


{:ok, _sup} = Horde.DynamicSupervisor.start_link([strategy: :one_for_one, name: HordeTestSup, automatic_shutdown: :never])

{:ok, child1} = Horde.DynamicSupervisor.start_child(HordeTestSup, %{id: :child1, start: {BasicGenServer, :start_link, [0]}})
{:ok, child2} = Horde.DynamicSupervisor.start_child(HordeTestSup, %{id: :child2, start: {BasicGenServer, :start_link, [0]}})
{:ok, child3} = Horde.DynamicSupervisor.start_child(HordeTestSup, %{id: :child3, start: {BasicGenServer, :start_link, [0]}})

Process.exit(child1, :kill)
IO.puts("Sent :stop_normal message to child of TestHordeSup")
children = Horde.DynamicSupervisor.which_children(HordeTestSup)

if Enum.count(children, fn {_id, _pid, _type, mod} -> [BasicGenServer] == mod end) != 3 do
  raise "Not 3 BasicGenServers for TestHordeSup"
else
  IO.puts("3 children for TestHordeSup!")
end

Will add this to branch as well.

from horde.

gmdorf avatar gmdorf commented on August 25, 2024

@derekkraan #270

from horde.

gmdorf avatar gmdorf commented on August 25, 2024

Could our discussion on our ElixirForum here be relevant? https://elixirforum.com/t/horde-dynamicsupervisor-terminate-child-is-not-working/61558/3?u=gavid

from horde.

gmdorf avatar gmdorf commented on August 25, 2024

I have added the equivalent tests to the branch. Please let me know if you see anything you need improved or if certain tests are meant to fail e.g. per our discussion linked in previous message

from horde.

derekkraan avatar derekkraan commented on August 25, 2024

Hi, I have looked at your tests and I understand now what the issue is. Horde.DynamicSupervisor only supports being called by name, not by the pid returned by Horde.DynamicSupervisor.start_link/3.

The reason for this is that Horde.DynamicSupervisor.start_link/3 starts a Supervisor with a number of children, one of them being the Horde.DynamicSupervisorImpl, which is where the name is registered to. The pid returned is really only meant to be used by the supervision tree. Usually you will start Horde.DynamicSupervisor in a supervision tree, and never see the pid.

So when you use the pid returned to start a new child, you are not running that child under Horde.DynamicSupervisor, but under a regular supervisor in the local supervision tree.

It's not possible to resolve this inconsistency without a major rewrite of the lib.

I hope this clarifies things. If you have any suggestions on how to improve the docs to make this more clear, I would consider a PR for that.

from horde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.