consuldotnet icon indicating copy to clipboard operation
consuldotnet copied to clipboard

KV Txn call may deadlock

Open danielglennross opened this issue 6 years ago • 3 comments

Missing CAF here: https://github.com/PlayFab/consuldotnet/blob/master/Consul/KV.cs#L614

Causes deadlock when the call is made in a Sync context (i.e. caller blocks with GetAwaiter().GetResult())

danielglennross avatar Aug 28 '18 12:08 danielglennross

I have the same issue when running integration tests concurrently. Multiple threads try to get keys using GetAwaiter().GetResult() and deadlock occurs.

sharkadi-a avatar Jan 18 '19 11:01 sharkadi-a

Use Task.Run() and then get Task.Result, this works correctly.

sharkadi-a avatar Jan 18 '19 13:01 sharkadi-a

True, but this isn't ideal - Using Task.Run, we're just releasing the current thread & offloading the work onto a threadpool thread instead. Ideally, we want the async call: await req.Execute(ct) to return execution without having to synchronize to the original context (via configureAwait(false)) so that we can 'sync over async' in our calling code if needed.

It seems this does happen here: https://github.com/PlayFab/consuldotnet/blob/master/Consul/KV.cs#L409

I'm guessing, the missing CAF on the awaitable in Txn() is not intended

danielglennross avatar Jan 18 '19 16:01 danielglennross