samsondav / rihanna

Rihanna is a high performance postgres-backed job queue for Elixir
MIT License
439 stars 49 forks source link

UndefinedFunctionError: function nil.id/0 is undefined #81

Open potibas opened 5 years ago

potibas commented 5 years ago

This error is showing up quite frequenly on Sentry.IO for my application:

UndefinedFunctionError: function nil.id/0 is undefined
  ?, in nil.id/0
  File "lib/rihanna/job_dispatcher.ex", line 67, in Rihanna.JobDispatcher.handle_info/2
  File "gen_server.erl", line 637, in :gen_server.try_dispatch/4
  File "gen_server.erl", line 711, in :gen_server.handle_msg/6
  File "proc_lib.erl", line 249, in :proc_lib.init_p_do_apply/3

From what I can gather, it's trying to mark a job as successful, but the job that has been popped from the map is nil.

  def handle_info({ref, result}, state = %{pg: pg, working: working}) do
    # Flush guarantees that any DOWN messages will be received before
    # demonitoring. This is probably unnecessary but it can't hurt to be sure.
    Process.demonitor(ref, [:flush])

    {job, working} = Map.pop(working, ref) # ==> JOB GETS POPPED HERE

    case result do
      {:error, _} ->
        job_failure(job, result, pg)

      :error ->
        job_failure(job, result, pg)

      _ ->
        Rihanna.Job.mark_successful(pg, job.id)  # ==> JOB IS NIL AT THIS POINT ?!?
    end

    state = Map.put(state, :working, working) 

    {:noreply, state}
  end

I'm using Rihanna version 2.0.0 on Elixir 1.8.1 with Erlang/OTP 21.

samsondav commented 5 years ago

Hm... not a clue. The only time I've ever seen this is when I've manually deleted a job from the table.

Can you tell us a bit more about your setup? Are you doing anything non-standard?

manukall commented 5 years ago

Hi @samphilipd and @potibas, we're seeing the same error frequently. I don't think we're doing anything special. Any clue where to start debugging?

potibas commented 5 years ago

Pretty standard setup here as well. My jobs just download images from the Internet and upload to Google Cloud Storage.

We eventually moved our codebase from Rihanna to Oban, so can't say anymore... I do remember that I could not reproduce the issue but if I ran say, 100 or 200 jobs concurrently it normally popped up once or twice.