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

Server sent events does not work with proxy #1412

Closed
mfzl opened this issue Feb 8, 2017 · 5 comments
Closed

Server sent events does not work with proxy #1412

mfzl opened this issue Feb 8, 2017 · 5 comments

Comments

@mfzl
Copy link

mfzl commented Feb 8, 2017

1. What version of Caddy are you running (caddy -version)?

Caddy (untracked dev build)

2. What are you trying to do?

Make webpack auto reload functionality work which uses SSE

3. What is your entire Caddyfile?

    tls off
    gzip {
         not /__webpack_hmr
    }
    proxy /__webpack_hmr localhost:4002 {
        transparent
        header_upstream X-Real-IP {remote}
        header_upstream X-Forwarded-Server {host}
        header_upstream X-Forwarded-Host {host}
        keepalive 1000

    }

    proxy / localhost:4002 {
        except /__webpack_hmr
    }

    log stdout
    errors stderr

4. How did you run Caddy (give the full command and describe the execution environment)?

caddy

5. What did you expect to see?

SSE endpoint to continue sending events

6. What did you see instead (give full error messages and/or log)?

Connection breaks after about 30s with the following error on chrome:
net::ERR_INCOMPLETE_CHUNKED_ENCODING

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

Proxy the following with above Caddyfile
https://github.com/kljensen/golang-html5-sse-example

Check connections being made. It should terminate the connection after 25s - 35s and open a new connection to event stream

Also, I've compiled caddy with go version go1.8rc3 linux/amd64 because of #1355

@mfzl
Copy link
Author

mfzl commented Feb 8, 2017

I've noticed that in response headers Connection:keep-alive is not set. Which is why I set keepalive but it doesn't change anything, so it can be removed.

@mfzl
Copy link
Author

mfzl commented Feb 8, 2017

It works with timeoutes none. I'm not sure if that is how it should be. Please close the issue if it is so.

But then it disables timeouts for the entire block. Anyway to only disable timeouts for a certain URL while still proxying to the same service?

Maybe caddy could disable timeouts if upstream sends the header Connection: keep-alive?

@mholt
Copy link
Member

mholt commented Feb 8, 2017

Go lets us set timeouts for the HTTP server, not per-request. So this is not a bug, you just have to choose a decent timeout. Disabling them honestly isn't all that bad, just re-enable them if you find yourself being slowlorised. But the number of people who are using Caddy to do advanced things like proxying SSE are fewer I'd suspect than the number of people who are simply using Caddy to serve static files.

@mholt mholt closed this as completed Feb 8, 2017
@Ahnfelt
Copy link

Ahnfelt commented Feb 21, 2017

Well, it's almost trivially true that the number of people who use SSE are less than the total number of users! :) But then again, the front page says "Serve the web like it's 2017", and I think that means HTTP/2 and some kind of server push, and SSE is likely the best solution when you have HTTP/2.

Of course you can disable timeouts, but in the documentation it states that you shouldn't:

Disable all timeouts (not recommended unless you trust the clients):
timeouts none

In our case, we need the timeout for non-SSE, so we have something behind Caddy to reintroduce a timeout, but this complicates the setup, so it would be nice with support for this. Just my 👍

@mholt
Copy link
Member

mholt commented Feb 21, 2017

@Ahnfelt I'd like it too, but there was this go bug: golang/go#16450 and now this one: golang/go#18437 - which might be stepping on your toes a bit here. Also golang/go#16100 would be nice, but ultimately we're at the mercy of the Go standard lib here.

For now, in your case, you'll have to disable the timeouts and then hope for the best. Sorry!

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

No branches or pull requests

3 participants