Search code examples
scalaplayframeworkserver-sent-eventschunked-encoding

Server-Sent Events with Play: response only received when process killed


I'm trying to get the sample webapp play-streaming-scala to run and in some circumstances I get a weird behavior.

I've got the app running directly on port 80 of some host and I'm checking the output with curl -iv --raw http://somehost/scala/eventSource/liveClock.

What I'm expecting is something like this:

* Hostname was NOT found in DNS cache
*   Trying 195.176.3.71...
* Connected to somehost (0.0.0.0) port 80 (#0)
> GET /scala/eventSource/liveClock HTTP/1.1
> User-Agent: curl/7.39.0
> Host: somehost
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Content-Type: text/event-stream; charset=utf-8
Content-Type: text/event-stream; charset=utf-8
< Date: Wed, 18 Jan 2017 13:24:55 GMT
Date: Wed, 18 Jan 2017 13:24:55 GMT

< 
10
data: 14 24 56


10
data: 14 24 56


10
data: 14 24 56

etc., and clearly see the chunks appear one after the other as time goes by.

Now, on some machines, this works well. On some others on campus, this fails. curl only shows this and then stops:

*   Trying 195.176.3.71...
* Connected to somehost (0.0.0.0) port 80 (#0)
> GET /scala/eventSource/liveClock HTTP/1.1
> Host: somehost
> User-Agent: curl/7.43.0
> Accept: */*
> 

Now the interesting thing is: if I kill the webapp on the host, curl suddenly “catches up” and spits all the chunks together, closing the connection like this:

10
data: 14 35 20


* transfer closed with outstanding read data remaining
* Closing connection 0
curl: (18) transfer closed with outstanding read data remaining

What can be causing the behavior? What on earth is going on and intercepting these events? Is there any way I can “force flush” something from the Play response?


Solution

  • Turns out the local “hidden” proxy set up automatically by OS X's parental controls system is not forwarding chunked responses properly, thus making a system based on Server-Sent Events inoperable. A shame.