Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSTHRD103: Analyzer unable to detect synchronous wait call in asynchronous function that returns IAsyncEnumerable #633

Closed
t-bzhan opened this issue Jun 2, 2020 · 1 comment · Fixed by #702
Assignees

Comments

@t-bzhan
Copy link

t-bzhan commented Jun 2, 2020

Bug description

Analyzer rule VSTHRD002 is unable to detect synchronous wait call in in asynchronous function that returns IAsyncEnumerable.

Repro steps

Use below code snippet:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace vsthreadtest
{
    class Program
    {
        static async Task Main(string[] args)
        {
            await foreach(var i in FooAsync())
            {
                Console.WriteLine(i);
            }
        }

        public static async IAsyncEnumerable<int> FooAsync()
        {
            await Task.Delay(TimeSpan.FromSeconds(5));
            foreach (int i in Enumerable.Range(1, 10))
            {
                Task.Delay(TimeSpan.FromSeconds(5)).Wait();
                yield return i;
            }
        }

        public static IEnumerable<int> Foo()
        {
            foreach (int i in Enumerable.Range(1, 10))
            {
                Task.Delay(TimeSpan.FromSeconds(5)).Wait();
                yield return i;
            }
        }
    }
}

Expected behavior

All the Task.Delay(TimeSpan.FromSeconds(5)).Wait() calls will be detected.

Actual behavior

Task.Delay(TimeSpan.FromSeconds(5)).Wait() in FooAsync is not detected by VSTHRD002.
image
.

  • Version used: "Microsoft.VisualStudio.Threading.Analyzers 16.6.13"
  • Application (if applicable):

Additional context

I only test the behavior of application targeted "netcoreapp3.1".

@AArnott AArnott self-assigned this Oct 29, 2020
@AArnott AArnott changed the title VSTHRD002: Analyzer unable to detect synchronous wait call in asynchronous function that returns IAsyncEnumerable VSTHRD103: Analyzer unable to detect synchronous wait call in asynchronous function that returns IAsyncEnumerable Oct 29, 2020
@AArnott
Copy link
Member

AArnott commented Oct 29, 2020

VSTHRD002 only highlights synchronous blocks in non-async Type returning methods. VSTHRD103 is the analyzer that should flag this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants