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

Important delay with streams (Mozilla EventSource) #503

Closed
Kernald opened this issue Jul 8, 2016 · 10 comments
Closed

Important delay with streams (Mozilla EventSource) #503

Kernald opened this issue Jul 8, 2016 · 10 comments
Labels

Comments

@Kernald
Copy link

Kernald commented Jul 8, 2016

I'm exposing through Traefik an home-assistant instance. It's using Mozilla's EventSource to send events back to the front-end.

If I'm accessing directly the home-assistant instance, events are nearly instant. If I access it through Traefik, they are sent, but with an important delay (between 30 seconds and a minute or two). It looks like a buffer flush occurs every x seconds: if I send a lot of events, they are sent quickly. If I only have one or two, they are queued for a while.

It may be a feature, but not documented anywhere (or at least I couldn't find it). If it is, is there any way to configure the behavior?

@emilevauge
Copy link
Member

@Kernald hum, this weird... I would be very interested by reproducing this to investigate.
Could you give me more details ?

@Kernald
Copy link
Author

Kernald commented Jul 8, 2016

@emilevauge The way I checked this was pretty simple, with curl: my home-assistant instance has been running for long (I was proxying it through nginx until recently). I noticed some delay in the UI, so I subscribed two curl instances to my home-assistant: one through Traefik, the other one directly to the home-assistant webserver (the same port that Traefik backend uses), using this curl arguments exactly: curl -X GET -H "x-ha-access: YOUR_PASSWORD" -H "Content-Type: application/json" http://localhost:8123/api/stream.

I then sent some events from the web UI: the curl instance bound to the home-assistant webserver received them in a second. The other one, bound to Traefik, didn't until a long time (the home-assistant server send some pings every minute or so, some traffic is generated even when idling).

I tried another approach: flood the stream with events. I turned the lights on, off, on… both curl instances got the data really quickly. That's why I'm thinking of a buffer waiting to be full before being flushed.

Note that I didn't found anything relevant on Traefik's debug logs, nor on home-assistant's.

I'm not a web developer at all, so I can't set up a sample web-server right now, but I'll definitely try. You can probably reproduce the issue with a blank home-assistant instance (as it's sending some ping even without any components), which is available on Docker.

Don't hesitate if you need anything more until I can reproduce a minimal example!

@emilevauge
Copy link
Member

Thanks @Kernald for your explanations, I will try to reproduce this issue.

@ashmckenzie
Copy link

I have a very basic API that uses HTML5 Server Sent Events (using the Content-Type: "text/event-stream" header) and observe the same behaviour. If I hit the application directly I receive an event every 5 secs but through Traefik (1.0), it blocks correctly but instead of receiving events every 5 seconds, I see the backlog of events come through after ~3 mins.

@ashmckenzie
Copy link

I created https://github.com/ashmckenzie/traefik_html5sse_example to replicate the issue 😄

@emilevauge
Copy link
Member

emilevauge commented Jul 12, 2016

@ashmckenzie thanks a lot !
Fix is coming.

@ldez ldez added the kind/bug/confirmed a confirmed bug (reproducible). label Apr 29, 2017
@bsideup
Copy link

bsideup commented Jul 3, 2017

Hi @emilevauge,

I use the latest Traefik and it doesn't seem to work.

My server sends transfer-encoding: chunked + Content-Type: text/event-stream, if I access the endpoint, I see the events.
But if I run Traefik it front of it, I don't see any events coming.

Is there any option to disable buffering/caching/whatever completely?
Thanks!

@kelunik
Copy link

kelunik commented Dec 14, 2017

I have a similar issue, but with a generic content-type, not text/event-stream. An option or header that disables buffering would be really helpful.

@juliens
Copy link
Member

juliens commented Dec 14, 2017

@kelunik Can you try with 1.5.0-rc2 ?

@kelunik
Copy link

kelunik commented Dec 14, 2017

@juliens Sure. Seems all fine there. 👍

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

No branches or pull requests

8 participants