无法启动RedisClientSupervisor子进程-Elixir + Phoenix

时间:2019-05-16 08:32:30

标签: redis elixir phoenix-framework

我正在使用Elixir 1.7.2Phoenix运行一个应用程序,但是它在我的一个子进程中因错误而随机崩溃。

我正在使用一个名为redix-{:redix, ">= 0.6.1"}的模块,该模块正在处理与Redis的连接。

它崩溃并出现以下错误:

2019-05-16T07:29:08.929601+00:00 app[web.1]: 07:29:08.929 [info] Running ReviewedoWeb.Endpoint with Cowboy using http://:::46402
2019-05-16T07:29:09.191365+00:00 app[web.1]: 07:29:09.191 [info] Application reviewedo exited: Reviewedo.Application.start(:normal, []) returned an error: shutdown: failed to start child: Reviewedo.RedisClientSupervisor
2019-05-16T07:29:09.191385+00:00 app[web.1]: ** (EXIT) shutdown: failed to start child: Reviewedo.Accounts.Cache
2019-05-16T07:29:09.191387+00:00 app[web.1]: ** (EXIT) an exception was raised:
2019-05-16T07:29:09.191393+00:00 app[web.1]: ** (ArgumentError) the user in the Redis URI is ignored and should not be present, got: "h"
2019-05-16T07:29:09.191394+00:00 app[web.1]: (redix) lib/redix/uri.ex:30: Redix.URI.password/1
2019-05-16T07:29:09.191396+00:00 app[web.1]: (redix) lib/redix/uri.ex:15: Redix.URI.opts_from_uri/1
2019-05-16T07:29:09.191397+00:00 app[web.1]: (redix) lib/redix.ex:290: Redix.start_link/2
2019-05-16T07:29:09.191398+00:00 app[web.1]: (stdlib) supervisor.erl:365: :supervisor.do_start_child/2
2019-05-16T07:29:09.191399+00:00 app[web.1]: (stdlib) supervisor.erl:348: :supervisor.start_children/3
2019-05-16T07:29:09.191400+00:00 app[web.1]: (stdlib) supervisor.erl:314: :supervisor.init_children/2
2019-05-16T07:29:09.191402+00:00 app[web.1]: (stdlib) gen_server.erl:365: :gen_server.init_it/2
2019-05-16T07:29:09.191403+00:00 app[web.1]: (stdlib) gen_server.erl:333: :gen_server.init_it/6
2019-05-16T07:29:10.716373+00:00 app[web.1]: {"Kernel pid terminated",application_controller,"{application_start_failure,reviewedo,{{shutdown,{failed_to_start_child,'Elixir.Reviewedo.RedisClientSupervisor',{shutdown,{failed_to_start_child,'Elixir.Reviewedo.Accounts.Cache',{'EXIT',{#{'__exception__' => true,'__struct__' => 'Elixir.ArgumentError',message => <<\"the user in the Redis URI is ignored and should not be present, got: \\"h\\"\">>},[{'Elixir.Redix.URI',password,1,[{file,\"lib/redix/uri.ex\"},{line,30}]},{'Elixir.Redix.URI',opts_from_uri,1,[{file,\"lib/redix/uri.ex\"},{line,15}]},{'Elixir.Redix',start_link,2,[{file,\"lib/redix.ex\"},{line,290}]},{supervisor,do_start_child,2,[{file,\"supervisor.erl\"},{line,365}]},{supervisor,start_children,3,[{file,\"supervisor.erl\"},{line,348}]},{supervisor,init_children,2,[{file,\"supervisor.erl\"},{line,314}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,365}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,333}]}]}}}}}},{'Elixir.Reviewedo.Application',start,[normal,[]]}}}"}
2019-05-16T07:29:10.717128+00:00 app[web.1]: Kernel pid terminated (application_controller) ({application_start_failure,reviewedo,{{shutdown,{failed_to_start_child,'Elixir.Reviewedo.RedisClientSupervisor',{shutdown,{failed_to_start_child,'Elixir
2019-05-16T07:29:10.719206+00:00 app[web.1]: 
2019-05-16T07:29:13.269465+00:00 heroku[web.1]: State changed from up to crashed
2019-05-16T07:29:13.189754+00:00 app[web.1]: Crash dump is being written to: erl_crash.dump...done
2019-05-16T07:29:13.256383+00:00 heroku[web.1]: Process exited with status 1

崩溃前我没有做任何源代码更改,所以我不确定是什么原因。

我看到的错误是这个: https://github.com/whatyouhide/redix/blob/master/lib/redix/uri.ex#L31

似乎正在尝试拆分我的redis_url来获取用户名和密码,但是它正在为用户提供h。为我生成的redis_url类似于以下内容:

redis://h:pf851f7d83mf93nrand0mha5hsh8kgl3h4334k73d82580bba59d4c237f33f24752c76c@ec2-45-81-27-450.region.compute.amazonaws.com:18324

以下是发生错误的模块:

defmodule Reviewedo.RedisClientSupervisor do
  @moduledoc """
  Initiates Redis
  """
  use Supervisor
  alias Reviewedo.Accounts.Cache

  def start_link do
    Supervisor.start_link(__MODULE__, [])
  end

  def init(_) do
    redis_url = System.get_env("REDIS_URL") || "redis://127.0.0.1:6379"

    children = [
      worker(Cache, [redis_url, :redix], [])
    ]

    supervise(children, strategy: :one_for_one)
  end
end
defmodule Reviewedo.Accounts.Cache do
  @moduledoc """
  Provides cache functionality
  """

  def start_link(connection, name) do
    Redix.start_link(connection, name: name)
  end

  def query(param), do: Redix.command(:redix, param)

  def get(key), do: query(["get", key])
  def set(key, value), do: query(["set", key, value])
  def expire(key, seconds), do: query(["expire", key, seconds])
  def del(key), do: query(["del", key])

  def all_keys!() do
    case query(["keys", "*"]) do
      {:ok, keys} -> keys
      _ -> raise Reviewedo.RedisConnectionError, query: "all_keys!/1"
    end
  end

  def flushdb do
    query(["flushdb"])
    :ok
  end
end

defmodule Reviewedo.RedisConnectionError do
  @moduledoc """
  Raised when a Cache query returns an error

  This exception is raised by `Reviewedo.Accounts.Cache` and `Reviewedo.Accounts.CacheAPI` which:
  """

  defexception [:message]

  def exception(query: query) do
    msg = "Redis connection error, calling query: `#{query}`"
    %Reviewedo.RedisConnectionError{message: msg}
  end
end

似乎无法从opts获得我的uri,但是我不确定为什么。该应用程序在本地运行良好,因此必须与Heroku上的配置有关。

任何人以前都经历过类似的事情或知道可能是什么问题吗?

谢谢!

0 个答案:

没有答案