Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rare NullReferenceException from ServerEndPoint.get_LastException() #1342

Closed
AdamOutcalt opened this issue Feb 3, 2020 · 2 comments
Closed

Comments

@AdamOutcalt
Copy link

AdamOutcalt commented Feb 3, 2020

We've been using 2.0.601 for months, and only seen one instance of this - seems pretty rare.

Exception=System.NullReferenceException: Object reference not set to an instance of an object.
   at StackExchange.Redis.ServerEndPoint.get_LastException()
   at StackExchange.Redis.ExceptionFactory.PopulateInnerExceptions(ReadOnlySpan`1 serverSnapshot)
   at StackExchange.Redis.ExceptionFactory.NoConnectionAvailable(Boolean includeDetail, Boolean includePerformanceCounters, RedisCommand command, Message message, ServerEndPoint server, ReadOnlySpan`1 serverSnapshot)
   at StackExchange.Redis.ConnectionMultiplexer.GetException(WriteResult result, Message message, ServerEndPoint server)
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteAsyncImpl[T](Message message, ResultProcessor`1 processor, Object state, ServerEndPoint server)
   at StackExchange.Redis.RedisBase.ExecuteAsync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisDatabase.HashGetAllAsync(RedisKey key, CommandFlags flags)
   at StackExchange.Redis.KeyspaceIsolation.WrapperBase`1.HashGetAllAsync(RedisKey key, CommandFlags flags)

I'm sorry that I'm not more familiar with this project to contribute more. My best guess is on this line:

if (tmp2?.LastException != null && tmp2.LastException.Data.Contains("Redis-FailureType") && !tmp2.LastException.Data["Redis-FailureType"].ToString().Equals(nameof(ConnectionFailureType.UnableToConnect)))

The first clause checks that LastException is not null; but maybe it can be set to null on PhysicalBridge.OnFullyEstablished, and then the later checks may be working with null? I'm not sure when that event may fire relative to execution.

Otherwise, maybe there's a way for Data to not be populated?

@mgravell
Copy link
Collaborator

mgravell commented Feb 4, 2020

Sounds like a race condition in the LastException getting cleared. Will make the code more defensive, i.e. snapshot the values rather than access them multiple times.

@AdamOutcalt
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants