-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Caddy Doesn’t Seem to Flush Response Buffer, Breaking Reverse Proxy of Server-Sent Events #4247
Labels
bug 🐞
Something isn't working
Comments
Thanks for the great report -- am looking for someone who has Node handy who can try to reproduce this. |
francislavoie
added a commit
that referenced
this issue
Aug 3, 2021
I went through the commits that touched stdlib's `reverseproxy.go` file, and copied over all the changes that are to code that was copied into Caddy. The commits I pulled changes from: - golang/go@2cc3473 - golang/go@a5cea06 - golang/go@ecdbffd - golang/go@2189852 -golang/go@ca3c0df - golang/go@9c017ff This may also fix #4247 because of the change to `copyResponse` to set `mlw.flushPending = true` right away.
francislavoie
added a commit
that referenced
this issue
Aug 12, 2021
I went through the commits that touched stdlib's `reverseproxy.go` file, and copied over all the changes that are to code that was copied into Caddy. The commits I pulled changes from: - golang/go@2cc3473 - golang/go@a5cea06 - golang/go@ecdbffd - golang/go@2189852 -golang/go@ca3c0df - golang/go@9c017ff This may also fix #4247 because of the change to `copyResponse` to set `mlw.flushPending = true` right away.
mholt
pushed a commit
that referenced
this issue
Aug 12, 2021
I went through the commits that touched stdlib's `reverseproxy.go` file, and copied over all the changes that are to code that was copied into Caddy. The commits I pulled changes from: - golang/go@2cc3473 - golang/go@a5cea06 - golang/go@ecdbffd - golang/go@2189852 -golang/go@ca3c0df - golang/go@9c017ff This may also fix #4247 because of the change to `copyResponse` to set `mlw.flushPending = true` right away.
mholt
added
bug 🐞
Something isn't working
and removed
help wanted 🆘
Extra attention is needed
labels
Aug 12, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caddyfile
A simple Node.js web server running at
127.0.0.1:4000
:Start the server and the reverse proxy:
When I make a request to the server directly (without Caddy), I get the response I expect:
Note how the response headers came through.
But when I request via Caddy, the following happens:
Note how the response headers didn’t arrive.
In both cases the connection is kept open, which is the intended behavior.
Why Is This an Issue?
As far as I can tell, browsers doesn’t fire an
open
event on theEventSource
until the headers are received.Other Things I Tried without Success (They Don’t Seem to Affect the Behavior at All):
Change my Caddyfile to use
flush_interval -1
(see https://caddy.community/t/v2-server-sent-events-from-flask-to-caddy-via-gunicorn/7806/2).Rewrite my Node.js server to read like the following (see Server Sent Events are not working in a nodejs/express app #3765):
(Weirdly enough, writing it this way makes it not work even when I make the request to the Node.js server directly, without Caddy in the middle. Using a
.flushHeaders()
right after the call to.writeHead()
seems to fix it.)My Suspicion: The
flush_interval
configuration seems to be ignored, regardless of whether it was set explicitly in theCaddyfile
or it was set by Caddy itself because the responseContent-Type
istext/event-stream
(see https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#streaming and https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/streaming.go#L104-L108).A Workaround: Send a dummy server-sent event to force Caddy to flush the headers:
Versions
The text was updated successfully, but these errors were encountered: