Utf8JsonWriter.FlushAsync does not work in IIS on dotnet 10
- 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
I have an ActionResult defined (see below) whose purpose is to stream a large amount of data without having to load it all in memory.
This used to work fine, both locally and in production, in dotnet 9, but after installing dotnet 10, it stopped working in production.
In production, where we use IIS, after upgrading to dotnet 10 it will only return empty responses, but locally (without IIS), it still works.
Adding `await context.HttpContext.Response.BodyWriter.FlushAsync()` immediately after I flush the writer resolves the issue.
I have searched for breaking changes in dotnet 10 without finding anything, so I assume it is a bug.
class MyActionResult : ActionResult
{
private readonly IAsyncEnumerable _items;
public ExportingActionResult(IAsyncEnumerable items)
{
_items = items;
}
public override async Task ExecuteResultAsync(ActionContext context)
{
await using var writer = new Utf8JsonWriter(context.HttpContext.Response.BodyWriter, _options);
writer.WriteStartArray();
int count = 0;
await foreach (var item in _items)
{
writer.WriteStartObject();
writer.WriteString("key"u8, item.Key);
writer.WriteEndObject();
if (++count % 100 == 0)
{
await writer.FlushAsync();
}
}
writer.WriteEndArray();
}
}
### Expected Behavior
The behavior should be the same in dotnet 9 and dotnet 10, or it should be documented as a breaking change.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
10.0.103
### Anything else?
_No response_
Contributor guide
Research direction
Start with the MyActionResult.ExecuteResultAsync example using Utf8JsonWriter.FlushAsync and Response.BodyWriter.FlushAsync, then reproduce the empty response under IIS on .NET 10.0.103 and compare it with local hosting and .NET 9. Done means the response streams consistently, or the behavior is documented as a breaking change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100