Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to start a Horde dynamic supervisor with a registered name? #234

Open
iacobson opened this issue Jul 11, 2021 · 2 comments
Open

Comments

@iacobson
Copy link

I try something like (simplified)

  def start_link(name) do
    Horde.DynamicSupervisor.start_link(__MODULE__, [], name: name)
  end

  def via(name), do: {:via, Horde.Registry, {MyApp.DistributedRegistry, name}}

and trying to start it with

    Horde.DynamicSupervisor.start_child(MyApp.DistributedSupervisor, {__MODULE__, name})

getting the error

{:error,
 {%Protocol.UndefinedError{
    description: "",
    protocol: String.Chars,
    value: {:via, Horde.Registry, {Distributed.DistributedRegistry, "hello"}}
  },
  [
    {String.Chars, :impl_for!, 1, [file: 'lib/string/chars.ex', line: 3]},
    {String.Chars, :to_string, 1, [file: 'lib/string/chars.ex', line: 22]},
    {Horde.DynamicSupervisor, :start_link, 3,
     [file: 'lib/horde/dynamic_supervisor.ex', line: 131]},
    {Horde.ProcessesSupervisor, :start_child, 3,
     [file: 'lib/horde/processes_supervisor.ex', line: 766]},
    {Horde.ProcessesSupervisor, :handle_start_child, 2,
     [file: 'lib/horde/processes_supervisor.ex', line: 752]},
    {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 661]},
    {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 690]},
    {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
  ]}}

When tried to start with a simple string name (by mistake), I got the following error, which made me think the :via option should be possible

{:error,
 {:shutdown,
  {:failed_to_start_child, Horde.DynamicSupervisorImpl,
   {:EXIT,
    {%ArgumentError{
       message: "expected :name option to be one of the following:\n\n  * nil\n  * atom\n  * {:global, term}\n  * {:via, module, term}\n\nGot: \"hello\"\n"
     },
     [
       {GenServer, :do_start, 4, [file: 'lib/gen_server.ex', line: 943]},
       {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 379]},
       {:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 365]},
       {:supervisor, :"-start_children/2-fun-0-", 3,
        [file: 'supervisor.erl', line: 349]},
       {:supervisor, :children_map, 4, [file: 'supervisor.erl', line: 1157]},
       {:supervisor, :init_children, 2, [file: 'supervisor.erl', line: 315]},
       {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 374]},
       {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 342]}
     ]}}}}}
@ccapndave
Copy link

I've also run into this problem. It seems to be because of https://github.com/derekkraan/horde/blob/master/lib/horde/dynamic_supervisor.ex#L131 which assumes that name is a binary.

@derekkraan
Copy link
Owner

Hey, thanks for the issue. If someone wants to submit a PR that makes Horde work with via tuple semantics then I would be happy to merge that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants