Skip to content

Bug: Streaming endpoints aren't flushing hte http writers. #1764

Description

@perbu

Hi.

I'm working on a streaming (text/event-stream) example and I noticed the generated code doesn't flush the output properly. I've tracked this down to the code in pkg/codegen/templates/strict/strict-interface.tmpl, which looks something like this:

                    if closer, ok := response.Body.(io.ReadCloser); ok {
                        defer closer.Close()
                    }
                    _, err := io.Copy(w, response.Body)
                    return err

io.Copy will buffer the response, which would be fine for most cases, but would add an arbitrary delay on text/event-stream, which is pretty bad as the delay can easy be 10+ seconds. text/event-streams are often time-sensitive.

What we wanna do in here is to check the content-type and if it is text/event-stream, we wanna flush after each write. similar code is in the httputil/reverseproxy part of the stdlib in case anyone wants to see other places where text/event-stream is a special case.

Since fixing this would touch the generated code I thought I'd at least bring the topic up before trying to fix this myself. Let me know how I should proceed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions