Cannot start app after update with Erlang 24

After updating with Erlang 24 I cannot start app because the function :pg2.create/1 is undefined or private. Here is the response I get after executing mix phx.server

** (Mix) Could not start application wui: Wui.Application.start(:normal, []) returned an error: shutdown: failed to start child: Wui.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.PubSub.PG2
** (EXIT) shutdown: failed to start child: Phoenix.PubSub.PG2Server
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function :pg2.create/1 is undefined or private
(kernel 8.0) :pg2.create({:phx, Wui.PubSub})
(phoenix_pubsub 1.1.2) lib/phoenix/pubsub/pg2_server.ex:43: Phoenix.PubSub.PG2Server.init/1
(stdlib 3.15) gen_server.erl:423: :gen_server.init_it/2
(stdlib 3.15) gen_server.erl:390: :gen_server.init_it/6
(stdlib 3.15) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Any advice on how to proceed will be much appreciated. Thanks in advance.

:pg2 was deprecated some time ago and was scheduled to be removed on OTP24. You probably need to update the dependency and recompile the phoenix_pubsub to compile time selection of the implementation.

7 Likes

Thanks for the reply. I am not sure how to proceed and whether I interpreted your suggestion correctly. I compiled phoenix_pubsub with mix deps.compile phoenix_pubsub and now this dependency as reported by mix deps is

  • phoenix_pubsub 1.1.2 (Hex package) (mix)
    locked at 1.1.2 (phoenix_pubsub) 1f13f9f0
    ok

I still get the same error though when I run mix phx.server.

Yeah, updating Phoenix.PubSub to the latest should be enough to address the issue. The latest version is 2.0.0, so you will have to update your deps so you can bump to latest.

14 Likes

Thanks a million guys. I updated phoenix to 1.5.9 and phoenix_pubsub to 2.0.0 and now everything works fine!

3 Likes

This did not fix me, probably because I have a direct :pg2 call in my Application code:

def start(_type, _args) do
    children = [
      UserDocs.Repo,
      UserDocs.Vault,
      {Phoenix.PubSub, name: UserDocs.PubSub, adapter: Phoenix.PubSub.PG2}
    ]

    :pg2.create(UserDocs.PubSub)
    Supervisor.start_link(children, strategy: :one_for_one, name: UserDocs.Supervisor)
  end

I believe this came in with the phoenix boilerplate. I’ll have to replace this with whatever is current.

1 Like

You can simply remove that line. I don’t remember it being part of Phoenix but certainly these days it is not a necessary line.

Additionally as part of the Phoenix 1.4.x → 1.5.0 upgrade you should change that line to:

{Phoenix.PubSub, name: UserDocs.PubSub}

Assuming you’re already on Phoenix 1.5.x (which you probably should be if you want to be using OTP 24) I would take a close look at the upgrade guide to ensure that you’re not missing any of the other steps: phx-1.5-upgrade.md · GitHub

3 Likes