RedisTimeoutException when trying to connect to AWS ElasticCache Redis from App Runner

818 Views Asked by At

So we have an C# Web API project that connects to an AWS ElasticCache. It is an Redis cluster with just one node to test.

My connection string looks like this:

{NODE-ENDPOINT}:6379,ssl=True,sslProtocols=tls12,abortConnect=false,syncTimeout=10000

Tried both the cluster end-point as the end-point of the single node in the cluster. Both failed.

Locally it works but when we build the container and run it on the App Runner in AWS it gets the following error message:

StackExchange.Redis.RedisTimeoutException: The timeout was reached before the message could be written to the output buffer, and it was not sent, command=SETEX, timeout: 50000, inst: 0, qu: 0, qs: 0, aw: False, bw: CheckingForTimeout, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 1, serverEndpoint: {NODE-ENDPOINT}:6379, conn-sec: n/a, mc: 1/1/0, mgr: 10 of 10 available, clientName: ip-10-0-170-16(SE.Redis-v2.6.86.49666), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=3,Free=32764,Min=2,Max=32767), POOL: (Threads=5,QueuedItems=0,CompletedItems=534), v: 2.6.86.49666 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)

Checked with Reachability Analyzer if the interfaces can connect on port 6379. The status is 'Reachable' so that exclude network issues on AWS side. Also because the part 'The timeout was reached before the message could be written to the output buffer' i'm not sure if it is an connection issue or an issue on the C# / container. The code that I use to connect. First I register it in the IOC container;

var multiplexer = ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("Redis"));
builder.Services.AddSingleton<IConnectionMultiplexer>(multiplexer);

Then get it from IOC as _redis and use the following code to add a key

IDatabase db = _redis.GetDatabase();
RedisValue redisValue = new RedisValue("Test-Value");
TimeSpan ttl = TimeSpan.FromMinutes(10);
await db.StringSetAsync(new RedisKey(token), redisValue, ttl, false);

Again locally on my on local redis this works. But with the AWS ElasticCache I cannot get it working.

1

There are 1 best solutions below

0
On BEST ANSWER

This was so supid mistake. Solved it by the answer of unable to connect to Redis cluster using stackexchange.redis

It turned out, I didn't have Encryption in transit configured. So we should connect to the cluster without ssl. Changing the connection string in the following solved the problem:

{NODE-ENDPOINT}:6379,ssl=False,abortConnect=false,syncTimeout=10000