0

I have a .net 3.1 app (hosted in azure webjob) that uses azure redis for caching, I intermittently get this error when my app tries to get a value from the cache:

Exception : Timeout awaiting response (outbound=0KiB, inbound=0KiB, 5546ms elapsed, timeout is 5000ms), command=HMGET, next: HMGET App_Certificate, inst: 0, qu: 0, qs: 2, aw: False, rs: ReadAsync, ws: Idle, in: 0, serverEndpoint: [redis.server.host.taken.out]:6380, mc: 1/1/0, mgr: 10 of 10 available, clientName: xxxxxxxxxxxxxx, IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=2,Free=680,Min=4,Max=682), v: 2.2.4.27433 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)

The issue stopped happening when I restarted the webjob, what could be the issue?

Here's my redis config:

    services.AddStackExchangeRedisCache(options =>
    {
       options.Configuration = configuration.GetConnectionString("RedisConnection");
       options.InstanceName = string.Concat(applicationName, "_");
    });

Here's my redis implementation:

public static class DistributedCacheExtensions
{
    public static async Task SetRecordAsync<T>(this IDistributedCache cache, string recordId, T data, TimeSpan? absoluteExpiryTime = null, TimeSpan? unusedExpiryTime = null)
    {
        var options = new DistributedCacheEntryOptions()
        {
            AbsoluteExpirationRelativeToNow = absoluteExpiryTime ?? TimeSpan.FromMinutes(60),
            SlidingExpiration = unusedExpiryTime
        };

        var jsonData = JsonSerializer.Serialize(data);

        await cache.SetStringAsync(recordId, jsonData, options);
    }

    
    public static async Task<T> GetRecordAsync<T>(this IDistributedCache cache, string recordId)
    {
        var jsonData = await cache.GetStringAsync(recordId);

        if (jsonData is null)
        {
            return default(T);
        }

        return JsonSerializer.Deserialize<T>(jsonData);
    }
}
mahmoudmh
  • 51
  • 1
  • 7
  • did you check this article? SNAT port exhaustion is often an issue https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-intermittent-outbound-connection-errors – silent Aug 08 '23 at 09:38
  • Please refer to the below thread if helps https://stackoverflow.com/questions/56425997/it-was-not-possible-to-connect-to-the-redis-servers-connecttimeout – Naveen Sharma Aug 09 '23 at 10:00

0 Answers0