Hi, running Spray version 1.1.1.
I've implemented an actor to handle chunked streaming responses. It works for the most part, but I'm having trouble catching when the remote side closes the connection.
Here's some code from my actor's receive method:
case ev: Http.ConnectionClosed =>
emitMetrics(failure = Some(ev.toString))
log.warn("Stopping response streaming due to {}", ev)
context.stop(self)
case ev: Http.CloseCommand =>
emitMetrics(failure = Some(ev.event.toString))
log.warn("Stopping response streaming due to {}", ev)
context.stop(self)
If I make the request using curl and then kill it with ctrl-C while streaming, the actor gets a PeerClosed message which is picked up by the above code. It closes things down and everything is good.
However, if I make the request from a browser (specifically, from an <a> element with an href pointing at the Spray server, and a download disposition) and then cancel the in-progress download, the actor doesn't get any notification. It continues pulling data and trying to send it. Eventually it does emit an error to the log file: "Could not write response part MessageChunk, aborting connection". Even then, it doesn't seem to send a message to the actor, though that's a little unclear (I'm seeing the receive timeout firing in my actor hot on the heels of that error message).
I'd really like to be able to stop querying the datasource if a user cancels the streaming download... is there another message I should listen for? Is this just browser behavior I can't control?