1
votes

I'm having an issue with a phoenix app that is deployed on heroku. When I run this code locally, everything works fine, with no errors. When deploying to heroku, the app successfully deploys and starts up, but when using the app the GenServer the process crashes with this error:

[error] GenServer :main_worker terminating
** (exit) an exception was raised:
   ** (ErlangError) erlang error: :"function not exported"
       (elixir) Map.get_and_update!(%{"location" => %{"latitude" => 35.9628632, "longitude" => -86.8216522}, "name" => "Dover", "pickups" => 0}, "pickups", #Function<0.62518121/1 in BusTracker.MainWorker.handle_call/3>)
       (bus_tracker) lib/bus_tracker/main_worker.ex:27: BusTracker.MainWorker.handle_call/3
       (stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
       (stdlib) gen_server.erl:661: :gen_server.handle_msg/5
       (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
13:25:03.112 [error] GenServer #PID<0.319.0> terminating
** (exit) an exception was raised:
   ** (ErlangError) erlang error: {{:undef, [{Map, :get_and_update!, [%{"location" => %{"latitude" => 35.9628632, "longitude" => -86.8216522}, "name" => "Dover", "pickups" => 0}, "pickups", #Function<0.62518121/1 in BusTracker.MainWorker.handle_call/3>], []}, {BusTracker.MainWorker, :handle_call, 3, [file: 'lib/bus_tracker/main_worker.ex', line: 27]}, {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 629]}, {:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 661]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}, {GenServer, :call, [:main_worker, {:update_pickups, {"Dover", 1}}, 5000]}}
       (elixir) lib/gen_server.ex:356: GenServer.call/3
       (bus_tracker) web/channels/main_channel.ex:38: BusTracker.MainChannel.handle_in/3
       (phoenix) lib/phoenix/channel/server.ex:210: Phoenix.Channel.Server.handle_info/2
       (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
       (stdlib) gen_server.erl:681: :gen_server.handle_msg/5
       (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

Here are is the code that the error references.

   defmodule BusTracker.MainWorker do
     use GenServer
     # . . .

     # Server
25>  def handle_call({:update_pickups, {name,num}}, _, state) do
26>    waypoint = state.waypoints[name]
27>    {_, new_waypoint}  = Map.get_and_update! waypoint, "pickups",   fn(val) -> {"pickups", val + num} end
28>    {_, new_waypoints} = Map.get_and_update! state.waypoints, name, fn(val) -> {name, new_waypoint} end
29>    {_, new_state}     = Map.get_and_update! state, :waypoints ,    fn(val) -> {:waypoints, new_waypoints} end
30>    {:reply, new_waypoint["pickups"], new_state}
31>  end
     # . . . 
  end

I'm using these heroku build packs:

  • github.com/HashNuke/heroku-buildpack-elixir.git
  • github.com/gjaldon/heroku-buildpack-phoenix-static.git

and here is my elixir_buildpack.config:

# Erlang version
erlang_version=18.1.3

# Elixir version
elixir_version=1.0.4

# Always rebuild from scratch on every deploy?
always_rebuild=false

# Export heroku config vars
# config_vars_to_export=(DATABASE_URL)

# A command to run right after compiling the app
post_compile="pwd"

There is a mention of this in the elixir irc channel on Aug 5th, 2015, but I couldn't figure out how to solve the problem, with that discussion. I'm an elixir/erlang newbie, so can someone give me some help? Thanks

1
Are you running the same versions of Elixir and Erlang locally as you have defined in your buildpack? - Gazler
Wow, total newbie mistake. The versions in fact were different, so I updated to Elixir 1.1.1 in the build pack and the issue went away. Thanks @Gazler ! - Heath Attig
You should mark Gazler's answer as "accepted" when you can. - Onorio Catenacci

1 Answers

2
votes

Make sure you are using the same version of Elixir and Erlang on Heroku that you use in your development environment.

# Erlang version
erlang_version=18.1.3

# Elixir version
elixir_version=1.1.1