Elixir exrm release crashes on eredis start_link

373 views Asked by At

I'm fairly new to Elixir and this is the first app that I'm attempting to release using exrm. My app interacts with a Redis database for consuming jobs from a queue (using exq), and also stores results of processed jobs in Redis using eredis.

My app works perfectly when I run it via iex -S mix, and it also runs great when compiled into an escript. However when I use exrm, the application compiles without any issue, but it crashes when I run it.

This is the crash output:

$ ./rel/my_app/bin/my_app console
{"Kernel pid terminated",application_controller,"{application_start_failure,my_app,{bad_return,{{'Elixir.MyApp',start,[normal,[]]},{'EXIT',{{badmatch,{error,{{'EXIT',{{badmatch,{error,{undef,[{eredis,start_link,[],[]},{'Elixir.MyApp.Cache',init,1,[{file,\"lib/my_app/cache.ex\"},{line,8}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,306}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}}},[{'Elixir.MyApp.Cache',start_link,1,[{file,\"lib/my_app/cache.ex\"},{line,21}]},{supervisor,do_start_child,2,[{file,\"supervisor.erl\"},{line,314}]},{supervisor,handle_start_child,2,[{file,\"supervisor.erl\"},{line,685}]},{supervisor,handle_call,3,[{file,\"supervisor.erl\"},{line,394}]},{gen_server,try_handle_call,4,[{file,\"gen_server.erl\"},{line,607}]},{gen_server,handle_msg,5,[{file,\"gen_server.erl\"},{line,639}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}},{child,undefined,'Elixir.MyApp.Cache',{'Elixir.MyApp.Cache',start_link,[[{host,\"127.0.0.1\"},{port,6379},{database,0},{password,[]},{reconnect_timeout,100},{namespace,<<>>},{queues,[<<\"elixir\">>]}]]},permanent,5000,worker,['Elixir.MyApp.Cache']}}}},[{'Elixir.MyApp.Supervisor',start_cache,1,[{file,\"lib/my_app/supervisor.ex\"},{line,17}]},{'Elixir.MyApp.Supervisor',start_link,0,[{file,\"lib/my_app/supervisor.ex\"},{line,9}]},{'Elixir.MyApp',start,2,[{file,\"lib/my_app.ex\"},{line,10}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}

Here is the mix.exs for my application:

defmodule MyApp.Mixfile do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "0.0.1",
      name: "MyApp",
      elixir: "~> 1.0",
      escript: escript_config,
      deps: deps
    ]
  end

  def application do
    [
      applications: app_list(Mix.env),
      mod: { MyApp, [] },
      env: [ queue: 'elixir']
    ]
  end

  def included_applications do
    [ :logger, :httpoison, :eredis, :exq, :dotenv, :exjsx, :ex_doc, :oauth2, :sweet_xml ]
  end

  defp app_list(:dev), do: [:dotenv | app_list]
  defp app_list(_), do: app_list
  defp app_list, do: [:logger, :httpoison]

  def escript_config do
    [ main_module: MyApp ]
  end

  defp deps do
    [
      { :dotenv, github: "avdi/dotenv_elixir" },
      { :eredis, github: "wooga/eredis", tag: "v1.0.5" },
      { :exjsx, "~> 3.1.0" },
      { :exq, "~> 0.1.0", app: false },
      { :exrm, "~> 0.16.0" },
      { :ex_doc, github: "elixir-lang/ex_doc" },
      { :httpoison, "~> 0.4" },
      { :oauth2, "~> 0.1.1" },
      { :sweet_xml, "~> 0.2.1" }
    ]
  end
end

The crash appears to be happening in the following init function, where I call :eredis.start_link:

defmodule MyApp.Cache do
  use GenServer

  require Logger

  def init(client_opts) do
    { :ok, client } = :eredis.start_link(
        client_opts[:host],
        client_opts[:port],
        client_opts[:database],
        client_opts[:password],
        client_opts[:reconnect_timeout])
  end
end

Could it be because eredis is an Erlang library as opposed to Elixir?

1

There are 1 answers

1
bitwalker On BEST ANSWER

You need to add :eredis to your app_list function, so that it is packaged with the release, that goes for the rest of your dependencies as well.