spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Events are "stuck" in server-sent events stream #1049

Closed blancqua closed 8 years ago

blancqua commented 8 years ago

Our setup is as follows:

Having an endpoint for SSE:

@RequestMapping(method = GET, produces = "text/event-stream;charset=UTF-8") SseEmitter events();

This endpoint is being called through Zuul. Quite randomly we get the phenomenom that events are getting "stuck", meaning another event needs to be sent to push the "stuck" event to the client. I'm not 100% sure but after investigation it seems due to the fact that "Transfer-Encoding = chunked" is used (automatically set by Undertow as well as by Tomcat for persistent connections).

From [https://www.w3.org/TR/2011/WD-eventsource-20110208/]()

Authors are also cautioned that HTTP chunking can have unexpected negative effects on the reliability of this protocol. Where possible, chunking should be disabled for serving event streams unless the rate of messages is high enough for this not to matter.

A work-around that seems to do the trick is making sure "enough traffic" is put on the stream (sending heartbeats each second), but this ofcourse is not desirable. We might as well use polling then.

We're kind of puzzled here. Do you have any clue?

dsyer commented 8 years ago

I know that Hystrix sends a hearbeat. That's built into the Netflix code, so I assume the reason is something similar.