Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Thread safety when calling fetch_relation

Đang mở
#568 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
backend

Hướng nghiên cứu

Đọc lib/identity_cache/cached/recursive/association.rb quanh các dòng 25-42, bắt đầu với guard và việc loại bỏ @dehydrated_relation. Điều tra các lệnh gọi fetch_association đồng thời và xác minh rằng NameError đã được báo cáo không còn xảy ra khi truy cập đồng thời.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

https://github.com/Shopify/identity_cache/blob/313dfbcca210fdadd739268cfdcce01ff854f0b4/lib/identity_cache/cached/recursive/association.rb#L25-L42

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 👀

Ngôn ngữ chính
Ruby
Star
2k
Fork
175
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Shopify/identity_cache

Tất cả issue của Shopify/identity_cache

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.