Skip to content

Commit dcae5dd

Browse files
authored
Fix #2679: connect/config: only access task.Result if we know it completed (#2680)
* connect/config: only access task.Result if we know it completed * cite PR * typo
1 parent 0b4fd45 commit dcae5dd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Current package versions:
88

99
## Unreleased
1010

11+
- Fix [#2679](https://github.com/StackExchange/StackExchange.Redis/issues/2679) - blocking call in long-running connects ([#2680 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2680))
1112
- Support async cancellation of `SCAN` enumeration ([#2911 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2911))
1213
- Add `XTRIM MINID` support ([#2842 by kijanawoodard](https://github.com/StackExchange/StackExchange.Redis/pull/2842))
1314
- Add new CE 8.2 stream support - `XDELEX`, `XACKDEL`, `{XADD|XTRIM} [KEEPREF|DELREF|ACKED]` ([#2912 by mgravell](https://github.com/StackExchange/StackExchange.Redis/pull/2912))

src/StackExchange.Redis/ConnectionMultiplexer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,17 @@ private static ConnectionMultiplexer ConnectImpl(ConfigurationOptions configurat
681681
// note that task has timeouts internally, so it might take *just over* the regular timeout
682682
var task = muxer.ReconfigureAsync(first: true, reconfigureAll: false, log, null, "connect");
683683

684-
if (!task.Wait(muxer.SyncConnectTimeout(true)))
684+
if (task.Wait(muxer.SyncConnectTimeout(true)))
685685
{
686+
// completed promptly - we can check the outcome; hard failures
687+
// (such as password problems) should be reported promptly - it
688+
// won't magically start working
689+
if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer, muxer.failureMessage);
690+
}
691+
else
692+
{
693+
// incomplete - most likely slow initial connection; optionally
694+
// allow a soft failure mode
686695
task.ObserveErrors();
687696
if (muxer.RawConfig.AbortOnConnectFail)
688697
{
@@ -696,7 +705,6 @@ private static ConnectionMultiplexer ConnectImpl(ConfigurationOptions configurat
696705
}
697706
}
698707

699-
if (!task.Result) throw ExceptionFactory.UnableToConnect(muxer, muxer.failureMessage);
700708
killMe = null;
701709
Interlocked.Increment(ref muxer._connectCompletedCount);
702710

0 commit comments

Comments
 (0)