Azure / Azure/azure-functions-host

Find a way to prevent people from writing synchronous C# code

Open
#774 21 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

We ran into a couple cases (one [here](https://social.msdn.microsoft.com/Forums/azure/en-US/5c142d90-adef-4d7b-8a30-3224b6229d93/app-could-be-having-an-intermediat-issue-or-failing-to-start?forum=AzureFunctions)) where user's apps deadlocked because they were making synchronous outgoing http calls, e.g.

```
HttpResponseMessage response = client.PostAsync(url , httpContent).Result;
```

That causes the thread to be blocked while waiting for the response. Once you throw enough traffic at it, all the threads are blocked, and there are none left to get scheduled and do the work, so you have a deadlock. See http://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async.

@lindydonna suggested that we could potentially use Roslyn's analyzer to detect the situation and treat it as an error. Though it's an aggressive move, we really want to make it very hard for people to do this.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the proposed Roslyn analyzer approach and the synchronous HttpClient example, `client.PostAsync(url, httpContent).Result`. Determine how the analyzer should identify synchronous outgoing HTTP calls and whether treating them as errors is feasible. Done means the agreed cases are detected reliably and covered by analyzer tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.