Thread safety when calling fetch_relation
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Read lib/identity_cache/cached/recursive/association.rb around lines 25-42, starting with the guard and removal of @dehydrated_relation. Investigate concurrent fetch_association calls and verify that the reported NameError no longer occurs under concurrent access.
Written by the indexing model from the issue text.
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:
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 👀
- Dominant language
- Ruby
- Stars
- 2k
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Shopify/identity_cache
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Shopify/identity_cache#555 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Shopify/identity_cache#539 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Shopify/identity_cache#535 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Shopify/identity_cache#533 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Shopify/identity_cache#525 · 4 comments ·
All issues in Shopify/identity_cache
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
yegor256/rubocop-elegant#92 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
ecosyste-ms/awesome#812 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
forem/forem#23933 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rails/mission_control-jobs#347 ·