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

Rails app: NoMemoryError: Too deeply nested #204

Open
incorvia opened this issue Nov 3, 2022 · 3 comments
Open

Rails app: NoMemoryError: Too deeply nested #204

incorvia opened this issue Nov 3, 2022 · 3 comments

Comments

@incorvia
Copy link

incorvia commented Nov 3, 2022

When using Ruby on Rails I'm running into "NoMemoryError: Too deeply nested." with OJ's serialization within this gem. The suggested solution worked if I edited the OJ 'mode' to 'compat' and added the 'use_as_json' flag as follows:

    OJ_OPTIONS = {
      mode: :compat,
      # use ruby's built-in serialization.  If nil, OJ seems to default to ~15 decimal places of precision
      float_precision: 0,
      use_as_json: true
    }.freeze

The fact that no one else runs into this makes me wonder if maybe there is something about Rails specifically that is causing this though haven't tracked it down. If it's possible to modify these OJ options for everyone and tests still pass it could be suggested as a solution.

I'm happy to offer a PR if it would be accepted.

@tsrivishnu
Copy link

I'm running into the same problem too. In my case, it occurs when an activity is returning Ruby objects. If I simply change the Ruby objects to call #as_json on themselves and return the hash, it seems to be working. I haven't tried changing the OJ_OPTIONS.

@premist
Copy link

premist commented Nov 8, 2022

I'm experiencing this on plain Ruby project as well, doesn't seems like it's Rails related. Suggested workaround of modifying OJ_OPTIONS on gem source code mitigates it.

Update: Nevermind, I tried to reproduce this with the final workflow I ended up with, but can't reproduce it.

@bdchauvette
Copy link

We've run into this a few times, too. It usually seems to be caused by trying to serialize a model that has loaded recursive associations (e.g. book <-> author). OJ ends up in an infinite loop, and blows up.

In general, the default oj config does not seem to play nicely with ActiveRecord models, and accidentally returning an ActiveRecord instance can result in storing hundreds of KB as a workflow or activity result in Temporal 😬

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

No branches or pull requests

4 participants