-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
can't add a new key into hash during iteration lib/active_record/connection_adapters/abstract/query_cache.rb #40608
Comments
Can it be because it seems like this default proc needs it's own mutex |
We are experiencing the same behavior when upgrading to 6.1.1 in a preproduction environment, the error appears randomly, similar backtrace... Could be related somehow to these changes 8589e8c#diff-058ae7dda657cf52fe6046918ff3dc3e1f556588b9b81e5a9204eb768ac8063e? (long shot) |
@pauc Trying to fix it, i upgraded Ruby from 2.5.8 to 2.7.2 on production, but it did not solve the problem (but saved a few Mbs of RAM anyway), so i do not feel like it's Ruby version related |
We are experiencing this issue since we upgraded Rails to 6.1.3.1. Any insight on this issue? Did you manage to resolve it @kvokka ? |
Hey @jchatel But i'm happy to help you with it as much as i can. If you are willing to dig it, i can share Gemfile.lock content, so you'll be able to check for intersections with your project and hope that you will be more successful with this issue than me. |
We have same problem (randomly happened time to time) on 6.1.3.2 and ruby 2.7.3 with such trace:
The application code is just do |
Another randomly error has this trace while trying to achieve an association in application code:
All this does not look like "third party issue". Tried to grep query_cache manipulations in gemset with no luck. |
Is any of the participants using sentry-ruby here? We experienced this issue since we moved from sentry-raven to sentry-ruby and now have rolled back to sentry-raven. My hunch here is having two concurrent threads accessing the cache hash, in our case the sql_cache, schema_cache, in our case: |
@st0012 I'd reference getsentry/sentry-ruby#1183 even though it is closed it seems highly related. I can also confirm that since we rolled back to sentry-raven those errors don't appear anymore. Would you mind reopening it? |
We use |
@gsmetal do you report to sentry asynchronously? |
I can confirm that after we downgraded sentry-ruby to sentry-raven the error disappeared. @gsmetal Maybe some ActiveJob or other thread iterating over a caching hash in parallel? |
@boof Nope, it's just pure iterating over ActiveRecord's collection on list rendering. And I think this errors appeared after updating rails 6.0 -> 6.1. Just now found that we also have this error in separate sidekiq process on simple
WIll try to investigate this case deeper. |
@gsmetal Sidekiq itself uses worker threads to run jobs IMHO, so whenever another library to for example deep copy an object in parallel (see Hash#deep_dup implementations for example) while a new key/value pair is being written to the cache this can raise randomly. Maybe check for these kind of methods and debug from there. |
It seems that I found my problem. I realized that one of the possible cause could be prometheus_exporter which starts in separate Thread in puma and in sidekiq. Digging into this I found that it had issue with rails 6.1 on our version (0.5.4) so I've updated gem to latest (0.8.1) and we have no new occurrences in about a day for now. AFAIS this gem does not work with query cache directly, it works with connection pool and just raised error on 0.5.4. I didn't understand deeply what was causing the SUBJ error. |
There are different caches that can raise (schema, query, I think there is also one for views...). You can usually see which one looking at where the exception was raised. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
The issue is still highly reproducible. :(( UPDATE: We're using outdated version (known to have issue) of activerecord-import. Will update this comment whenever upgrade solved this for us or not. |
Probably unrelated, but sharing. Rails 6. Ruby 3.1.2p20 . M1. Big Sur. Development. Hit the error when doing complex param merging/permitting. h = ActionController::Parameters.new
# ... do stuff
# h.permit!.to_h.deep_symbolize_keys # ->
# RuntimeError Exception: can't add a new key into hash during iteration
h.permit!.to_hash.deep_symbolize_keys # works! |
We are facing the same issue after upgrade from rails 5.2.8 to rails 6.0.6.1 only on production environment, ruby 2.6. doing simple operation |
Steps to reproduce
Since it is caching problem, it is tricky to reproduce
Expected behavior
No error
Actual behavior
backlog from the first case:
yet another one:
System configuration
Rails version: 6.1.0.rc1
Ruby version: 2.5.8
Connect replaygaming/replaypoker#4860
Connect #24627
The text was updated successfully, but these errors were encountered: