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

Aperta
#169 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
csharp, redis
Ambito
backend

Direzione di ricerca

Inizia dal punto di ingresso GetFeatureState e segui OpenFeature.Api.Instance.GetClient("FsProvider") attraverso GetBooleanValueAsync, confrontando il percorso con e senza la lettura e la scrittura in featureCache. Verifica come il percorso di caching in memoria o Redis interagisce con il recupero asincrono del flag. Il lavoro è completato quando il primo recupero del flag restituisce il risultato e il valore viene memorizzato per il periodo previsto di 30 minuti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C#
Stelle
20
Fork
17
Merge medio
21h 47m
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Flagsmith/flagsmith-dotnet-client

Tutte le issue di Flagsmith/flagsmith-dotnet-client

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.