Skip to content

Issues with ActiveJob (+Sidekiq) reporting errors in jobs with serialized records #384

@lleger

Description

@lleger

I'm having issues with Raven reporting errors that happen inside of ActiveJob jobs when Raven is configured to send events in the background. When a job runs that triggers an exception, the background Raven job fires and eventually dies with this message:

ERROR: !!! ERROR HANDLER THREW AN ERROR !!!
ERROR: Can't serialize a Hash with reserved key "_aj_globalid"
ERROR: [edit]/activejob-4.2.4/lib/active_job/arguments.rb:126:in `serialize_hash_key'

I successfully reproduced this issues consistently in this test repository I created. It's a vanilla Rails 4.2.4 app, and all of the gems are up-to-date. I then added Raven and configured it to report in development and to report via background job. I also added Sidekiq. To exhibit the issue, perform the following steps:

  1. Clone the repo
  2. Migrate and seed the database
  3. Boot Sidekiq: bundle exec sidekiq
  4. Open up Rails console and run:
    • ExceptionJob.perform_later — successfully reports to Sentry
    • ExceptionJob.perform_later([]) — successfully reports to Sentry
    • ExceptionJob.perform_later(Post.first) — failure

My assumption is that it fails because of the ActiveJob serialization. When the Sentry reporter job gets run, it serializes a hash that includes the parameters sent to ActiveJob. You can see in ActiveJob's source that they have a RESERVED_KEYS hash. Since the parameters sent to ActiveJob would contain a hash that has these keys, it would make sense that that is causing the issue.

I also tested this against the ActiveJob inline adapter, but it didn't seem to have the same issues. I only tested it against Sidekiq, which is what I was using when I noticed the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions