-
Notifications
You must be signed in to change notification settings - Fork 279
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
DelayedJob integration should not call as_json on the payload object. #369
Comments
@fcheung have you tried using Oj as JSON serializer? It's the gem we suggest to use. We've had historiclal problems with to_json and as_json and we didn't find a solution to work on every project. Can you give us more details about the libraries you have installed? Thanks. |
I can reproduce the issue with this snippet (running against rails 4.2.5.1)
This produces a SystemStackError whether Oj is loaded or not. Since the call to |
This snippet shows what happens when rollbar is involved:
The call to invoke_job raises SystemStackError, because of the call by rollbar to User.as_json |
@fcheung thank you very much for the analysis. We'll try to reproduce the problem and fix it. |
@fcheung can you for now use this config options? We'll work on fix this soon. Thanks. |
I've just monkey patched rollbar for now - the remainder of the data is still good to have |
@fcheung nice, can you share what you coded for that? You just remove the data you don't want? |
It's a bodge - i just commented out https://github.com/rollbar/rollbar-gem/blob/master/lib/rollbar/delayed_job.rb#L20 job is an active record object (at least with the backend i use) so has a sane as_json method. handler ends up being a blob of yaml rather than a nice payload object but it's still pretty readable in general - for us it's never much more than a class name, method name & arguments (we tend to keep arguments to delayed jobs as just plain scalars/arrays/hashes rather than complex types) |
|
I see, I think I was using that solution but I found some problems in some scenarios. I'll check it, thanks! 😄 |
Just recently ran into this issue myself and am getting Stack Level too deep errors in my delayed_job workers when using Rollbar in them. The OJ gem does not seem to help. |
@trostli we'll need to review this. The bug is in ActiveSupport since it monkey patches Sorry for the inconveniences. |
This will avoid infinite loops with ActiveRecord class jobs. Fix #369
This will avoid infinite loops with ActiveRecord class jobs. Fix #369
The DelayedJob integration loads the payload object and tries to serialise it using as_json. If Delayed job has been used to delay a class method on an ActiveRecord subclass, this can have very unpredictable results, as one of the objects that will have
as_json
called on it is the class itself.ActiveSupport adds Object#as_json which iterates over all instance variables and calls as_json - unless classes implement their own as_json method it will recursively serialise all the instance variables of the class and the class instance variables of an active record subclass contains all sorts of stuff.
It can very easily lead to infinite recursion - in my case this happened via the use of aasm gem: it creates a class instance variable containing a state machine definition object, which itself has as an instance variable the class it was defined on.
Another bad thing is that active record objects appear to have a
relation
object containing the base scope for the model. Callingas_json
on this will attempt to dump the entire table to jsonThe text was updated successfully, but these errors were encountered: