question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Potential deadlocks due to .Result calls?

See original GitHub issue

Scanning through the code ready for the codeathon tomorrow, I’ve spotted a few .Result calls. One example is in SendRequestStatusToGetASmokeAlarm.Send, where it does this: _httpClient.SendAsync(request).Result. There are a few more examples though. This can cause deadlocks and should be avoided. I’ve lost countless hours in the past due to someone using .Result, and causing random deadlocks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
stevejgordoncommented, Feb 22, 2018

I agree that this should be fixed. If there are rare places we can’t do async all the way, we should record those and decide what the options are in each case.

Therefore I’d suggest the scope of this is to properly await any async calls wherever .Result or .GetAwaiter().GetResult() calls are made.

Good spot @dracan

2reactions
valdisiljuconokscommented, Feb 2, 2018

@dracan , @bernard-chen I’ve used AsyncHelper in cases when async is not possible due to framework, platform, library, whatever - and it does its job. Agree that those special cases have to isolated and treated very special - more like an exceptional situation and not normal one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'await' works, but calling task.Result hangs/deadlocks
Acquiring a value via an async method: var result = Task.Run(() => asyncGetValue()).Result;. Syncronously calling an async method. Task.
Read more >
Understanding Async, Avoiding Deadlocks in C# | by Eke ...
If called from threadpool thread then a theadpool thread is blocked, which will lead to a deadlock if the work load is high...
Read more >
Potential deadlock due to calling callbacks while holding a ...
As locks are acquired in reverse orders from two threads, a deadlock is possible. The fundamental issue is that we should not call...
Read more >
C# Deadlocks in Depth – Part 2
One potential danger manifests when you are using an async method from a non-async method. In those cases, you can use the .Result...
Read more >
Don't Block on Async Code
This kind of deadlock is always the result of mixing synchronous with asynchronous code. Usually this is because people are just trying out ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found