Skip to content

Swarm stops to respond when try to find name #145

Description

@wesleimp

If you try to run Swarm.whereis_name(name) while Swarm.register_name(name, Sup....) didn't finish yet, the application stops to respond.

defmodule MyDynamicSupervisor do
  use DynamicSupervisor

  # Initialization
  
  def register(name) do
    child_spec = %{
      id: MyActor,
      start: {MyActor, :start_link, [name]},
      restart: :transient
    }

    case DynamicSupervisor.start_child(__MODULE__, child_spec) do
      {:error, {:already_started, pid}} -> {:ok, pid}
      {:ok, pid} -> {:ok, pid}
    end
  end
end
defmodule MyActor do
  use GenServer

  def start_actor(name) do
    {:ok, pid} = Swarm.register_name(name, MyDynamicSupervisor, :register, [name])
  end

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

  def init(name) do
    pid = Swarm.whereis_name(name) # At this moment, the application stops to respond
    {:ok, name}
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions