Deadlock occurs for flag value fetching while using in memory or redis cache for flags

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

Maintainer thường phản hồi trong vòng 1 ngày

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ệ
csharp, redis
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu từ điểm đầu vào GetFeatureState và theo dõi OpenFeature.Api.Instance.GetClient("FsProvider") qua GetBooleanValueAsync, so sánh đường đi có và không có thao tác tra cứu và ghi vào featureCache. Kiểm tra cách đường đi caching trong bộ nhớ hoặc Redis tương tác với việc lấy flag bất đồng bộ. Hoàn tất khi lần lấy flag đầu tiên trả về và giá trị được lưu trong khoảng thời gian dự kiến là 30 phút.

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

Mô tả

How are you running Flagsmith
  • Self Hosted with Docker
  • Self Hosted with Kubernetes
  • SaaS at flagsmith.com
  • Some other way (add details in description below)
Describe the bug

I have added in memory or redis caching for flag values to control flagsmith API hits. But as soon as I add that the flag fetching for the first time becomes a never returning call and its like deadlock occurs.

Here is the code .
Do note that I am using the open feature sdk here for flagsmith provider.

Steps To Reproduce
// At the class level
private static readonly ConcurrentDictionary<string, (bool Value, DateTime Timestamp)> featureCache
     = new ConcurrentDictionary<string, (bool Value, DateTime Timestamp)>();`
   public static async Task<bool> GetFeatureState(string flagName, bool defaultValue, OpenFeature.Model.EvaluationContext context, string identity)
   {
       try
       {
           var CommonConfigValue = ConfigurationManager.AppSettings[flagName];
           var flagStatus = false;

           if (string.IsNullOrEmpty(CommonConfigValue) &&
               AppSettings._OpenFeatureProviderName.ToLower() == ProviderEnum.FlagSmith.ToString().ToLower())
           {
               var cacheflagName = $"{identity}:{flagName}";

               if (featureCache.TryGetValue(cacheflagName, out (bool Value, DateTime Timestamp) cachedEntry))
               {
                   SystemLogger.WriteInformation($"Found cached value for {cacheflagName}");
                   // Use cached value only if timestamp is within 30 minutes
                   if ((DateTime.Now - cachedEntry.Timestamp).TotalMinutes < 30)
                   {
                       SystemLogger.WriteInformation($"Using cached value for {cacheflagName}");
                       return cachedEntry.Value;
                   }
               }

               // Retrieve the Flagsmith client from the Application state
               var flagsmithClient = OpenFeature.Api.Instance.GetClient("FsProvider");

               // Check the feature flag asynchronously
               flagStatus = await flagsmithClient.GetBooleanValueAsync(flagName, defaultValue, context)
                                                 .ConfigureAwait(false);

               // Store value with timestamp
               featureCache[cacheflagName] = (flagStatus, DateTime.Now);
           }
           else
           {
               flagStatus = CommonConfigValue?.Trim().ToLower() == "true";
           }

           return flagStatus;
       }
       catch (Exception ex)
       {
           SystemLogger.WriteError($"Error checking feature state: {ex.Message}");
           return false;
       }
   }
Expected behavior

Flag value must be returned and stored in cache for 30 min time

Screenshots

No response

Ngôn ngữ chính
C#
Star
20
Fork
17
Merge trung bình
21 giờ 47 phút
Pull request đã merge (30 ngày)
8

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 Flagsmith/flagsmith-dotnet-client

Tất cả issue của Flagsmith/flagsmith-dotnet-client

Issue tương tự

Thêm issue về C#

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.