Fix #2679: connect/config: only access task.Result if we know it completed by mgravell · Pull Request #2680 · StackExchange/StackExchange.Redis

Expand Up @@ -681,8 +681,17 @@ private static ConnectionMultiplexer ConnectImpl(ConfigurationOptions configurat // note that task has timeouts internally, so it might take *just over* the regular timeout var task = muxer.ReconfigureAsync(first: true, reconfigureAll: false, log, null, "connect");
if (!task.Wait(muxer.SyncConnectTimeout(true))) if (task.Wait(muxer.SyncConnectTimeout(true))) { // completed promptly - we can check the outcome; hard failures // (such as password problems) should be reported promptly - it // won't magically start working if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer, muxer.failureMessage); } else { // incomplete - most likely slow initial connection; optionally // allow a soft failure mode task.ObserveErrors(); if (muxer.RawConfig.AbortOnConnectFail) { Expand All @@ -696,7 +705,6 @@ private static ConnectionMultiplexer ConnectImpl(ConfigurationOptions configurat } }
if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer, muxer.failureMessage); killMe = null; Interlocked.Increment(ref muxer._connectCompletedCount);
Expand Down