Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#log_job_exception gets wrong exception info when job can be retried #28

Closed
yiichou opened this issue Apr 19, 2022 · 2 comments
Closed
Labels

Comments

@yiichou
Copy link
Contributor

yiichou commented Apr 19, 2022

Sidekiq version: 6.4.1
Rails version: 6.0.3.6

If a failed job is able to be retried, Sidekiq will

  1. catch the really exception
  2. append the exception message to the job and push it into retry queue
  3. raise a new exception Sidekiq::JobRetry::Skip

So, when Sidekiq::LogstashJobLogger tries to parse the failed job by #log_job_exception,
the received exception is Sidekiq::JobRetry::Skip.

Finally, the recorded error_message, error and error_backtrace are wrong.

@yiichou
Copy link
Contributor Author

yiichou commented Apr 19, 2022

I have a patch to solve this problem, it tries to get really exception message from the enqueued retry job

def log_job_exception(job, started_at, exc)
  payload = setup_payload(job)

  payload['duration'] = elapsed(started_at)
  payload['message'] += ": fail: #{payload['duration']} sec"
  payload['job_status'] = 'fail'

  if exc.is_a? Sidekiq::JobRetry::Skip
    Sidekiq::RetrySet.new.scan(payload['jid'], 1) do |retried_job|
      payload['error_message'] = retried_job['error_message']
      payload['error_class'] = retried_job['error_class']
    end
  else
    payload['error_message'] = exc.message
    payload['error_class'] = exc.class
    payload['error_backtrace'] = %('#{exc.backtrace.join("\n")}')
  end

  process_payload(payload)
end

@iMacTia
Copy link
Owner

iMacTia commented Apr 19, 2022

Hi @yiichou, thanks for raising this.
I think I saw Sidekiq::JobRetry::Skip exceptions before, but they never posed to be a problem, this might be a combination of sidekiq/ruby/rails versions.

Do you think you might be able to come up with a PR that reproduces the issue so we can run it against all the CI matrix versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants