Remove indirection to mitigate a presumed deadlock. Fixes StackExchange/StackExchange.Redis#42. #353
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So I ran into this issue as well. After reading through some of the comments and taking a look at the code, I noticed an unnecessary indirection in
ConnectionMultiPlexer.ConnectImpl
which appears to be causing a deadlock:What's happening here is the code is spawning an async task which waits synchronously on an async task result. This is bad juju. What it appears is happening next is the code blocks the context thread waiting for the wrapper task created with
Factory.StartNew
to return:When the continuation from
ReconfigureAsync
returns, it waits for the context thread to become available. Since the context thread is blocked waiting for the continuation, it results in deadlock. Stephen Cleary has an excellent description of the pattern on his blog.The fix, I believe, is simple: spawn the
ReconfigureAsync
method directly:If I had to guess, I'd say
ReconfigureAsync
was once a synchronous method that was converted to async without updating theConnectImpl
implementation to remove the async wrapping.The above is conjecture at this point, however in my limited testing it appears to solve the problem.