Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
perbu opened this issue Sep 18, 2024 · 0 comments · May be fixed by #1765
Open

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

perbu opened this issue Sep 18, 2024 · 0 comments · May be fixed by #1765

Comments

@perbu
Copy link
Contributor

perbu commented Sep 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant