RPC to 'my_elixir_proj@127.0.0.1' failed, application start error

I am very novice to Phoenix/Elixir as I recently inherited a project where I was assigned to fix a bug. I’ve been successfully fixing bugs, rebuilding and restarting my elixir application on our production server but one day the start service stopped working.

Now after successfully compiling and building my elixir proj, when I try and start the application by running _build/prod/rel/my_elixir_proj/bin/my_elixir_proj start I am getting the following RPC error which I am clueless about.

RPC to 'my_elixir_proj@127.0.0.1' failed: {'EXIT',
                                            {{#{'__exception__' => true,
                                                '__struct__' => 'Elixir.KeyError',
                                                key => username,
                                                term => [{types,true},
                                                 {hostname,<<"localhost">>},
                                                 {types,true},
                                                 {name,
                                                  'Elixir.MyElixirProj.Repo.Pool'},
                                                 {otp_app,my_elixir_proj},
                                                 {repo,
                                                  'Elixir.MyElixirProj.Repo'},
                                                 {adapter,
                                                  'Elixir.Ecto.Adapters.Postgres'},
                                                 {database,
                                                  <<"barcode_manager_prod">>},
                                                 {pool_size,20},
                                                 {pool_timeout,5000},
                                                 {timeout,15000},
                                                 {adapter,
                                                  'Elixir.Ecto.Adapters.Postgres'},
                                                 {database,
                                                  <<"barcode_manager_prod">>},
                                                 {pool_size,20},
                                                 {pool,
                                                  'Elixir.DBConnection.Poolboy'},
                                                 {extensions,
                                                  [{'Elixir.Ecto.Adapters.Postgres.DateTime',
                                                    []},
                                                   {'Elixir.Postgrex.Extensions.JSON',
                                                    [{library,
                                                      'Elixir.Poison'}]}]},
                                                 {port,5432}]},
                                              [{'Elixir.Keyword','fetch!',2,
                                                [{file,"lib/keyword.ex"},
                                                 {line,333}]},
                                               {'Elixir.Postgrex.Protocol',
                                                startup,2,
                                                [{file,
                                                  "lib/postgrex/protocol.ex"},
                                                 {line,411}]},
                                               {'Elixir.Postgrex.Protocol',
                                                handshake,2,
                                                [{file,
                                                  "lib/postgrex/protocol.ex"},
                                                 {line,361}]},
                                               {'Elixir.DBConnection.Connection',
                                                connect,2,
                                                [{file,
                                                  "lib/db_connection/connection.ex"},
                                                 {line,134}]},
                                               {'Elixir.Connection',
                                                enter_connect,5,
                                                [{file,"lib/connection.ex"},
                                                 {line,622}]},
                                               {proc_lib,init_p_do_apply,3,
                                                [{file,"proc_lib.erl"},
                                                 {line,247}]}]},
                                             {gen_server,call,
                                              [<7269.2652.0>,
                                               {checkout,#Ref<7269.0.4.1836>,
                                                true,infinity},
                                               5000]}}}```

Any help would be great, thanks!

Here, let me convert that erlang error to elixir for you, might be more clear:

{:EXIT,
  {
    {
      %KeyError{
        key: :username,
        term: [
          types: :true,
          hostname: "localhost",
          types: true,
          name: MyElixirProj.Repo.Pool,
          otp_app: :my_elixir_proj,
          repo: MyElixirProj.Repo,
          adapter: Ecto.Adapters.Postgres,
          database: "barcode_manager_prod",
          pool_size: 20,
          pool_timeout: 5000,
          timeout: 15000,
          adapter: Ecto.Adapters.Postgres,
          database: "barcode_manager_prod",
          pool_size: 20,
          pool: DBConnection.Poolboy,
          extensions: [
            "Elixir.Ecto.Adapters.Postgres.DateTime": [],
            "Elixir.Postgrex.Extensions.JSON": [
              library: Poison
            ]
          ],
          port: 5432
        ]
      },
      [
        {Keyword, :fetch!, 2, [file: 'lib/keyword.ex', line: 333]},
        {Postgrex.Protocol, :startup, 2, [file: 'lib/postgrex/protocol.ex', line: 411]},
        {Postgrex.Protocol, :handshake, 2, [file: 'lib/postgrex/protocol.ex', line: 361]},
        {DBConnection.Connection, :connect, 2, [file: 'lib/db_connection/connection.ex', line: 134]},
        {Connection, :enter_connect, 5, [file: 'lib/connection.ex', line: 622]},
        {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}
      ]
    },
    {:gen_server, :call, [#Pid<7269.2652.0>, {:checkout, #Ref<7269.0.4.1836>, true, :infinity},5000]}
  }
}

The important bit is:

      %KeyError{
        key: :username,

I.E. it tried to lookup the username from the term of:

        [
          types: :true,
          hostname: "localhost",
          types: true,
          name: MyElixirProj.Repo.Pool,
          otp_app: :my_elixir_proj,
          repo: MyElixirProj.Repo,
          adapter: Ecto.Adapters.Postgres,
          database: "barcode_manager_prod",
          pool_size: 20,
          pool_timeout: 5000,
          timeout: 15000,
          adapter: Ecto.Adapters.Postgres,
          database: "barcode_manager_prod",
          pool_size: 20,
          pool: DBConnection.Poolboy,
          extensions: [
            "Elixir.Ecto.Adapters.Postgres.DateTime": [],
            "Elixir.Postgrex.Extensions.JSON": [
              library: Poison
            ]
          ],
          port: 5432
        ]

But the username does not exist, so a KeyError exception was thrown. I.E. it looks like the username was left out of the database connection information in your configuration (and password too it seems?). :slight_smile:

2 Likes

I have the username and password assigned by environment variables which I verified are set correctly. I should also note that I’ve successful start the application running the following command:

MIX_ENV=prod elixir --erl "-detached" -S mix phoenix.server