Skip to content

SseFormatter.WriteAsync does not flush after writing an event #64118

@erik-kallen

Description

@erik-kallen

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running my application in our production environment, our SSE endpoints did not work. The main difference between my dev environment (which works) and prod (which does not) is that in prod we are hosting in IIS.

It can be made to work by doing:

static async IAsyncEnumerable<T> FlushingIterator<T>(IAsyncEnumerable<T> inner, HttpResponse response)
{
    await foreach (var item in inner)
    {
        yield return item;
        await response.Body.FlushAsync();
    }
}
await SseFormatter.WriteAsync(FlushingIterator(GetMyEvents(), Response), Response.Body, cancellationToken);

but I find it unexpected that it does not do this out of the box.

Expected Behavior

The output stream should be flushed immediately after an event is written by the SseFormatter.

Steps To Reproduce

await SseFormatter.WriteAsync(GetMyEvents(), Response.Body, cancellationToken);

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions