#1677 ✓resolved

Not streaming SSE/EventSource in Chrome

Reported by carchrae | June 21st, 2013 @ 05:30 PM | in 1.3 (closed)

Framework version: 1.3.x branch - up to commit 0b9d70a7b1b556a9899fc35eee92dbc6a91632d9 (may 21, 2013)
Platform you're using: ubuntu 12.10

Reproduction steps: See code below, the events() controller with Chrome (Version 25.0.1364.160 Built on Ubuntu 12.10) does not display any events until the request is closed. Strangely, the other test (chunkTest()) writing only text seems to work fine.

Expected: When writing an SSE event using writeChunked it should appear instantly on the client.

Observed: In Chrome, with 1.3.x, it does not appear until the connection is closed. When Chrome reconnects automatically (as per EventSource), it begins to send the stream fine. 1.2.5 works.


I was trying to get Server Sent Events working which involves sending chunked responses. It never shows a result until the connection is dropped in Chrome.

Rather strangely, when Chrome reconnects, it will then send events correctly (EventSource automatically reconnects) - to see this restart the play server. This is a possible workaround - simply kick/close connections from Chrome on the first connection.

It works fine on Firefox, which I understand is more permissive about Chunked responses not being sized correctly. Play 1.2.5 works on Chrome and Firefox, no problem.

Below is some code that shows the issue. I wrote chunkTest thinking it would show the same problem, but suprisingly, it works (with the added Chrome hack of sending blank space - which is somewhat suspicious in itself - but posted elsewhere on the internet as a hack for Chrome - this is needed in 1.2.5 as well).

I had a good look at the writeChunk code - which has changed a lot. I'm not actually sure the problem is here. I tried copying the 1.2.5 code into the 1.3.x branch and I still could not get it to work correctly. I wonder if it has to do with the changes to the Netty Pipeline (which are awesome, I love being able to turn on Netty compression) or perhaps the Netty version?

I suspected that the Chunked length was being sent incorrectly, but when I debugged the two versions, they seemed to produce the same chunk length values. (I'm not sure they were correct, but they were the same).


public class EventSource extends Controller {

public static void chunkTest() {

    // hack to make chrome start displaying (needed in both 1.2.5 and 1.3.x)
    for (int x = 0; x < 5000; x++)
        response.writeChunk(" ");

    int i = 0;
    while (i++ < 10) {
        response.writeChunk(11 - i + " Why Hello!\n");



public static void events() throws IOException {
    response.contentType = "text/event-stream";

    //does not appear to be needed (or help on 1.3.x)
    for (int x = 0; x < 5000; x++)
        //this is a comment in event-stream
        response.writeChunk(": \n\n");

    int i = 0;
    while (i++ < 3) {
        response.writeChunk("event: message\ndata: hello " + i + "\n\n");

    response.writeChunk("data: bye\n\n");


See attached html file that connects to server.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2>Play framework</h2>

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the <a href="http://www.playframework.org">http://www.playframework.org</a> website.<br><br>

<h2>Source code is hosted on github</h2>Check out our repository at <a href="http://github.com/playframework/play">http://github.com/playframework/play</a><br><br>

<h2>Contributing, creating a patch</h2> Please read the <a href="http://play.lighthouseapp.com/projects/57987/contributor-guide">contributor guide</a><br><br>

<h2>Reporting Security Vulnerabilities</h2> Since all bug reports are public, please report any security vulnerability directly to <em>guillaume dot bort at gmail dot com</em>.<br><br>

<h2>Creating a bug report</h2> Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.<br><br>

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.<br><br>

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.


Referenced by