0
votes

I am currently having a problem running the phoenix server application. This error is displayed when I tried to access 'localhost:4000'. It is complaining that it cannot find memcached proc on runtime as shown below.

[error] #PID<0.558.0> running MyApp.Endpoint terminated Server: localhost:4000 (http) Request: GET /
** (exit) an exception was raised:
** (RuntimeError) cannot find memcached proc
    (plug_session_memcached) lib/plug_session_memcached.ex:130: Plug.Session.MEMCACHED.get/3
    (plug) lib/plug/session.ex:74: anonymous fn/5 in Plug.Session.fetch_session/1
    (plug) lib/plug/debugger.ex:211: Plug.Debugger.maybe_fetch_session/1
    (plug) lib/plug/debugger.ex:174: Plug.Debugger.render/6
    (plug) lib/plug/debugger.ex:153: Plug.Debugger.__catch__/5
    (myapp) lib/myapp/endpoint.ex:1: MyApp.Endpoint.call/2
    (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
    (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

Here are my dependencies:-

{:coherence, "~> 0.3"},
  {:comeonin, "~> 2.4"},
  {:cowboy, "~> 1.0"},
  {:excoveralls, "~> 0.5", only: :test},
  {:gettext, "~> 0.11"},
  {:httpoison, "~> 0.10.0"},
  {:lager, github: "basho/lager", tag: "3.2.4", override: true},
  {:mailgun, "~> 0.1.2"},
  {:mariaex, ">= 0.0.0"},
  {:mcd, github: "EchoTeam/mcd"},
  {:phoenix, "~> 1.2.1"},
  {:phoenix_ecto, "~> 3.0"},
  {:phoenix_html, "~> 2.6"},
  {:phoenix_live_reload, "~> 1.0", only: :dev},
  {:phoenix_pubsub, "~> 1.0"},
  {:plug_session_memcached, github: "gutschilla/plug-session-memcached"},
  {:timex, "~> 2.2.1"},
  {:timex_ecto, "~> 1.1.3"}

It is most likely an issue with my Plug.Session memcached settings in endpoint.ex because when i switched to using :cookies as my store, it works as intended but not for :memcached. Any help would be highly appreciated.

This is the code where it throws the argument error in Plug.Session.MEMCACHED

@max_tries 100

def init(opts) do
    Keyword.fetch!(opts, :table)
end

def get( conn, sid, table) do
    case :mcd.get( table, sid ) do
      {:error, :noproc}   -> raise ArgumentError, "cannot find memcached proc"
        {:error, :notfound} -> {nil, %{}}
        {:error, :noconn} -> {nil, %{}}
        {:ok, data }        -> {sid, data}
    end
end

def put( _conn, nil, data, table) do
    put_new(data, table)
end

def put( _conn, sid, data, table) do
    :mcd.set( table, sid, data )
sid
end

def delete( _conn, sid, table) do
    :mcd.delete(table, sid)
    :ok
end

defp put_new(data, table, counter \\ 0)
    when counter < @max_tries do
        sid = :crypto.strong_rand_bytes(96) |> Base.encode64
    put( nil, sid, data, table )
end
1
Have you followed all the instructions in the README of plug-session-memcached (especially adding those additions to application/0): github.com/gutschilla/plug-session-memcached#synopsis?Dogbert
yes, everything has been added. It has problems trying to get the sid from the memcached table and i am not sure whySean T.

1 Answers

0
votes

You didn't start plug_session_memcached or its dependencies.

Adjust your mix.exs like this (Quote from the README)

def application do
  [
    ...
    applications: [
        ...
       :lager, :corman # <-- add these both (mcd needs them)
    ],
    included_applications: [
        :plug_session_memcached # <--- add this entry
    ]
  ]
end