StackExchange/StackExchange.Redis

NRE on ConnectionMultiplexer.WaitAllIgnoreErrors

czd890 opened this issue · 3 comments

Sometimes this error is caught on the server (out of hundreds of instances, 1-2 times every 2-3 days).
I looked through the sourcecode and this NRE exception doesn't seem to be possible. 😢

{
    "exception": {
        "Type": "System.NullReferenceException",
        "TargetSite": "Boolean WaitAllIgnoreErrors(System.Threading.Tasks.Task[])",
        "Message": "Object reference not set to an instance of an object.",
        "Data": {},
        "Source": "StackExchange.Redis",
        "HResult": -2147467261,
        "StackTrace": "   
at StackExchange.Redis.ConnectionMultiplexer.WaitAllIgnoreErrors(Task[] tasks) 
in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 463\n   
at StackExchange.Redis.ConnectionMultiplexer.Close(Boolean allowCommandsToComplete) 
in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2301\n   
at StackExchange.Redis.ConnectionMultiplexer.Dispose() 
in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2259\n
in mycode stacks..."
    }
}

version: 2.7.33.41805

Do you know if this is happening during shutdown, e.g. possibly a usage while the ConnectionMultiplexer is being disposed?

I faced a similar issue, which reproduces occasionally when invoking ConnectionMultiplexer.CloseAsync().
Package: StackExchange.Redis 2.8.0

Executing code:

internal sealed class RedisConnection : IHostedService {
    // ...
    public async Task StopAsync(CancellationToken cancellationToken)
    {
        // ...
        await _multiplexer.CloseAsync();
        await _multiplexer.DisposeAsync();
    }
}

Exception:

System.NullReferenceException
Object reference not set to an instance of an object.
   at StackExchange.Redis.ConnectionMultiplexer.AllComplete(Task[] tasks) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 560
   at StackExchange.Redis.ConnectionMultiplexer.WaitAllIgnoreErrorsAsync(String name, Task[] tasks, Int32 timeoutMilliseconds, ILogger log, String caller, Int32 callerLineNumber) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 487
   at StackExchange.Redis.ConnectionMultiplexer.CloseAsync(Boolean allowCommandsToComplete) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2318
   at Lib.RedisConnection.StopAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StopAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.DisposeAsync()
   at Enhanced.Testing.Component.Component`1.StopAsync(CancellationToken cancellationToken)
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90

@NickCraver It's possible. Based on the existing logs, it's difficult to reproduce the detailed process during the failure.