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

Deadlock in Microsoft.AspNetCore.Mvc.Testing on .NET 7 #45233

Open
1 task done
z1c0 opened this issue Nov 22, 2022 · 4 comments
Open
1 task done

Deadlock in Microsoft.AspNetCore.Mvc.Testing on .NET 7 #45233

z1c0 opened this issue Nov 22, 2022 · 4 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Milestone

Comments

@z1c0
Copy link

z1c0 commented Nov 22, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The following combination causes a deadlock when trying to read HttpContext.Request.Body:

  • NET 7 (7.0.100)
  • Microsoft.AspNetCore.Mvc.Testing (7.0.0)
  • Using the Microsoft.AspNetCore.Hosting.HttpRequestIn.Start DiagnosticListener event.
  • Using synchronous IO to read the request body (e.g. ReadToEnd()).

The code snippet below is from the linked reproducer sample.
The call to ReadToEnd() hangs forever.

internal class KeyValueObserver : IObserver<KeyValuePair<string, object>>
{
    public void OnNext(KeyValuePair<string, object> kvp)
    {
        if (kvp.Key == "Microsoft.AspNetCore.Hosting.HttpRequestIn.Start")
        {
            var context = kvp.Value as HttpContext;
            
            var bodyControlFeature = context.Features.Get<IHttpBodyControlFeature>();
            bodyControlFeature.AllowSynchronousIO = true;
            
            var stream = new StreamReader(context.Request.Body);
            var body = stream.ReadToEnd();  // Hangs forever!
            body.ToString();
        }
    }
}

Running the same code with previous versions of .NET (Core) works without a problem.

Expected Behavior

The call should not hang as with previous versions.

Steps To Reproduce

Reproducer project: https://github.com/z1c0/Mvc.TestingHang
Run the unit test method BasicTests.TestPost.

  • NET 7.0: The test hangs forever
  • NET 6.0: The test terminates and the request body can be read correctly.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

I could reproduce the problem on Windows, Linux, and macOS.
The same code worked fine with previous versions (.NET Core 3.1, .NET 5.0, .NET 6.0 on all platforms).

@javiercn javiercn added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Nov 22, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 8 Planning milestone Nov 23, 2022
@ghost
Copy link

ghost commented Nov 23, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@MehdiNaz
Copy link

I am getting the same error

@MehdiNaz
Copy link

please help me
ERORRRRRR
Microsoft.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 285) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

1 similar comment
@MehdiNaz
Copy link

please help me
ERORRRRRR
Microsoft.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 285) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jun 20, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@captainsafia captainsafia modified the milestones: .NET 8 Planning, Backlog Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
No open projects
Status: No status
Development

No branches or pull requests

7 participants