Redis: NOAUTH Authentication required


I’m having trouble with Redis with auth when client loses connection and tries to reconnect. I’m getting exception ServiceStack.Redis.RedisResponseException : NOAUTH Authentication required.

Below you can reproduce this error with unit test which is modified unit test of Does_retry_failed_commands:

public void Does_retry_failed_commands_auth()
	// -> Redis must have "requirepass testpassword" in config
	var connstr = "testpassword@localhost";

	var redisCtrl = new RedisClient(connstr); //RedisConfig.DefaultHost

	var redis = new RedisClient(connstr);

	var clientInfo = redisCtrl.GetClientsInfo();
	var redisId = clientInfo.First(m => m["name"] == "redisRetry")["id"];
	Assert.That(redisId.Length, Is.GreaterThan(0));

	Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

	redis.OnBeforeFlush = () =>
		redisCtrl.KillClients(withId: redisId);

	Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
	Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));

	Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
	Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
	Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));

Thank you for help!


Thanks for the repro! This was a tricky issue due to trying to re-connect in the middle of a processing a command which resulted in a dirty write buffer. The fix was to send all required commands upon re-connection (like setting AUTH password on the connection) directly to the socket (i.e outside of the write buffer) which was added in this commit.

This change is available from v4.0.55 that’s now available on MyGet.

Hi Mythz,

Thank you very much for ultra-fast response and for the solution. You simply did it and reconnecting is working. I’ve been experiencing this error for the last three days on Azure Cache, with your help this problem is solved, but what remains is the question why the connection to Azure Redis drops in the first place.

Original error is: “An existing connection was forcibly closed by the remote host” and I suspect that this error probably has nothing to do with ServiceStack, but nevertheles any idea is welcomed and appreciated.

Thank you again for your time.

This is TCP Socket exception saying that the remote server dropped the TCP connection, nothing we can do other than try to auto-reconnect.

Weird I just started getting this error today, glad I’m upgrading to .56 this week.