Response stops when `Response.Body.WriteAsync` is called a lot under IIS
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
If you call `Response.Body.WriteAsync` very often in IIS or IIS Express, the response will stop completely. Oddly enough, the `WriteAsync` call occurs at 100,000 times, but not at 50,000 times.
The same does not occur when using the Kestrel server. It seems to occur only under IIS and .NET 6.0.
This was a problem when using libraries such as SharpZipLib for stream processing. Buffering the response alleviated the problem, but it appears that this problem is caused by the number of times, not the size, of the response.
### Expected Behavior
Identical behavior (no stoppage of response) is achieved in IIS and Kestrel.
### Steps To Reproduce
### Repro code
```csharp
using System.Text;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseHttpsRedirection();
app.MapGet("/download", async (HttpResponse response) =>
{
var data = Encoding.UTF8.GetBytes("hello");
for (var i = 0; i < 100000; i++)
{
await response.Body.WriteAsync(data);
}
await response.Body.FlushAsync();
});
app.Run();
```
### Test result
```
C:\Users\shibayan>curl -v https://localhost:44320/download
* Trying 127.0.0.1:44320...
* Connected to localhost (127.0.0.1) port 44320 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> GET /download HTTP/1.1
> Host: localhost:44320
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Server: Microsoft-IIS/10.0
< X-Powered-By: ASP.NET
< Date: Tue, 18 Oct 2022 06:36:55 GMT
<
hello^C <= stuck
```
### Exceptions (if any)
_No response_
### .NET Version
6.0.402
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.