#1677 ✓ resolved
carchrae

Not streaming SSE/EventSource in Chrome

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

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.

Details:

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).

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6
http://skrb.org/ietf/http_errata.html#chunk-size
http://en.wikipedia.org/wiki/Chunked_transfer_encoding

public class EventSource extends Controller {

public static void chunkTest() {
    response.setContentTypeIfNotSet("text/plain");
    response.writeChunk("Hello\n");

    // 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) {
        await(1000);
        response.writeChunk(11 - i + " Why Hello!\n");
    }

    await(1000);
    response.writeChunk("...Blastoff?\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) {
        await(1000);
        response.writeChunk("event: message\ndata: hello " + i + "\n\n");
    }

    await(1000);
    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 »

Play framework

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 http://www.playframework.org website.

Source code is hosted on github

Check out our repository at http://github.com/playframework/play

Contributing, creating a patch

Please read the contributor guide

Reporting Security Vulnerabilities

Since all bug reports are public, please report any security vulnerability directly to guillaume dot bort at gmail dot com.

Creating a bug report

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.

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

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.

Shared Ticket Bins

Attachments

Referenced by

Pages