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

Abierto
#169 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
csharp, redis
Área
backend

Línea de trabajo

Comienza en el punto de entrada GetFeatureState y sigue OpenFeature.Api.Instance.GetClient("FsProvider") a través de GetBooleanValueAsync, comparando la ruta con y sin la consulta y escritura en featureCache. Comprueba cómo la ruta de caché en memoria o Redis interactúa con la obtención asíncrona del flag. Se considera terminado cuando la primera obtención del flag devuelve el resultado y el valor se almacena durante el periodo esperado de 30 minutos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C#
Estrellas
20
Forks
17
Merge medio
21 h 47 min
PR fusionados (30 d)
8

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Flagsmith/flagsmith-dotnet-client

Todos los issues de Flagsmith/flagsmith-dotnet-client

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.