Description
Hi!
We utilize a global, in-memory cache with TTL for one of our models per process. We also wanted to use identity_cache
so that the whole object tree is fetched with one network call.
However, we receive rare errors when we call fetch_association
with the following stack trace:
NameError instance variable @dehydrated_relation not defined
/usr/local/bundle/ruby/3.3.0/gems/identity_cache-1.5.6/lib/identity_cache/cached/recursive/association.rb:34
/usr/local/bundle/ruby/3.3.0/gems/identity_cache-1.5.6/lib/identity_cache/cached/recursive/association.rb:19
which points to this piece of code:
identity_cache/lib/identity_cache/cached/recursive/association.rb
Lines 25 to 42 in 313dfbc
Since the code has a guard clause: record.instance_variable_defined?(dehydrated_variable_name)
, the only way this can happen is that another thread is concurrently executing the same code and has already removed this instance variable.
Are you open to contributions to fix concurrency issues? So far we've only seen this error popping up dozens of times on ~50M requests, however, there might be more that we haven't seen yet or are failing silently 👀