mix ecto.create does not work due to the plug_crypto issue

Hi all,

I have a problem with setting up simple phoenix app with mix phx.new. Weirdest thing is - it worked last week without a problem and now I don’t know what I changed (I am almost sure it was nothing) and why it’s not working.

Problem: when creating new project with mix phx.new, after I cd into new directory and run mix ecto.create I get:

10:39:36.405 [error] GenServer #PID<0.292.0> terminating
** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private
    (crypto 5.0.2) :crypto.hmac(:sha256, "postgres", <<236, 186, 74, 106, 223, 211, 23, 71, 163, 135, 42, 171, 252, 96, 232, 70, 0, 0, 0, 1>>)
    (postgrex 0.15.0) lib/postgrex/scram.ex:52: Postgrex.SCRAM.hash_password/6
    (postgrex 0.15.0) lib/postgrex/scram.ex:26: Postgrex.SCRAM.verify/2
    (postgrex 0.15.0) lib/postgrex/protocol.ex:734: Postgrex.Protocol.auth_cont/4
    (postgrex 0.15.0) lib/postgrex/protocol.ex:579: Postgrex.Protocol.handshake/2
    (db_connection 2.4.0) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

As stated - this was working already before. I tried to uninstall everything phoenix/elixir related and redeploy. I am pretty sure the versions did not change.
I googled that error and it seems it was related to the deprecation of that function in OTP24, but that was some time ago (not over the weekend). In my mix.exs I see following entries:

      {:plug, "~> 1.12"},
      {:plug_crypto, "~> 1.1.2 or ~> 1.2"},

It would mean I have the latest dependencies there.
I am rather new to phoenix so I would need some guidance on where to look next.

Update - I tried with 1.6.0-rc.1 and it worked fine. I will stick to it for now, but any hint on why it happened before would be still welcome.

Wild guess, postgrex is using a function from a newer OTP version now.

Another wild guess, you did not run into that issue last week, because you were using locked versions, but in your newest project, it installed the latest postgrex version (because afaik postgrex in phoenix is anything above 0.0.0)

You can open the mix.lock file in one of your older projects, and lock ecto and posgrex to the same versions, or you can try to update your Elixir/OTP version.

EDIT: give me a message if you don’t know what I am talking about :smiley:

1 Like