aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

PostAsJsonAsync causes "SocketException: Connection reset by peer" error because Content-Length header is missing #242

Closed merijndejonge closed 3 years ago

merijndejonge commented 5 years ago

Hi, I just encountered a weird issue when running my aspnet core web services in an Azure Kubernetes, environment.

I repeatedly received a "SocketException: Connection reset by peer" error when one web service calls another using PostAsJsonAsync(...). This issues did not occur when running the services outside K8S/Azure.

By inspecting the code of PostAsJsonAsync, I figured out that it eventually makes the following call to PostAsync:

client.PostAsync(requestUri, content, cancellationToken);

This call fails with the socket exception message.

It turned out that content did not have a Content-Length header. If I add this header to content and then make the call, everything works as expected.

This raises two questions:

  1. Why is this issue popping up in the K8S/Azure environment? Am I doing something wrong?
  2. Why isn't the Content-Length header not added by PostAsJsonAsync. Is this a bug?

Any help to resolve this is greatly appreciated.

mkArtakMSFT commented 3 years ago

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now.