GetServerRole got Issue

Hi Teams,

We’re currently using ServiceStack.Redis.Core version 5.9.2. Previously, to make our logs informative, we used to inquire about the Host and Server Role every time we attempted to Get and Retrieve data from Redis.

However, sometimes (occasionally) we encountered issues like this while accessing GetServerRole().

2023-08-08 19:42:52.5599 [DEBUG] [] Xtremax.Cache.RedisCacheClientServiceStack Use Host: 10.92.35.180:6379 
2023-08-08 19:42:52.5599 [ERROR] [] Xtremax.Cache.RedisCacheClientServiceStack Failed to store cache with key '358e0836-14d8-4bef-abc6-dd62eab99464', reason : Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object.
   at ServiceStack.Redis.RedisClient.GetServerRole() in C:\BuildAgent\work\b2a0bfe2b1c9a118\src\ServiceStack.Redis\RedisClient.cs:line 1070
   at Xtremax.Cache.RedisCacheClientServiceStack._Store(String key, Object value, TimeSpan ttl)
   at Xtremax.Cache.RedisCacheClientServiceStack.Store(String key, Object value, Double ttlSeconds)

What happened with that issue?
How should we proceed when encountering that issue?

Are you referring to this previous forum post? We would still need a way to reproduce the error. It’s hard when the issue is transient and possibly environment specific. You could try a sample application in a docker environment maybe if you need multiple servers/clients?

Regarding this issue, again you’ve said it happens sometimes (occasionally). Looking at the code path it looks like there is a possibility that if the network response is null the resolving of the base.Role method in GetServerRole could result in a null reference which we could throw a seperate/specific error or alternate response for, but this will still fail to resolve the server role, so your application would also need to handle that. One option would be wrap that line in a try catch if you can’t upgrade. In the latest version of ServiceStack we are now handling this to return an unknown role, updated in this commit.

Since you are seeing multiple different occasional issues seems to be the root cause will be environmental or network related. What environment are your systems running in? Does your monitoring see any other issues at the same time periods?

It’s a tricky one to track down, but from your previous post there wasn’t anything obvious that you shared that would cause such a problem that we know of.

No, cases are different, we have 2 projects that use our same Redis Cache but they use different Environment, one uses kubernetes and redis sentinel (see this issue) and one uses IIS Windows and not redis sentinel. The problem with GetServerRole() is from a project that uses IIS and doesn’t use redis sentinel
And as for the issue from the previous forum post we still don’t know why it’s only happening in the production env and currently the issue never appears again and also in the dev env we never find that issue.

Thank you for your recommendation