The basis of what I am trying to do is stream a large file hosted on S3 to
a client over http, e.g Client <---> Server <---> S3 (client is a web
browser/rest client)
Everything is working fine apart from when the client disconnects halfway
through the transfer. All the streams/futures seem to finish with the
corresponding error but the file is still being retrieved in the background
by the server.
Here is some simple code which demonstrates my problem:
val connectionFlow = Http().outgoingConnection(host =
"mirror.internode.on.net")
val source = Source.single(HttpRequest(uri =
"http://mirror.internode.on.net/pub/test/1000meg.test"))
val outerFuture = source.via(connectionFlow).runWith(Sink.head)
var count = 0
outerFuture.onSuccess {
case response =>
val innerFuture = response.entity.dataBytes.mapAsync(1)(bytes => {
count += bytes.length
if (count > 150000) Future.failed(throw new
RuntimeException("Simulate client disconnecting"))
else Future.successful(bytes)
}).runWith(Sink.onComplete {
case res => println("inner complete: ", res);
})
}
outerFuture.onComplete {
case res => println("outer complete: ", res);
}
This runs as expected with the output:
[info] Running StreamTest
[info] (outer complete: ,Success(HttpResponse(200....
[info] (inner complete: ,Failure(java.lang.RuntimeException: Simulate
client disconnecting))
Which all looks good except I can still see that the file is being
downloaded by looking at my network traffic and netstat.
Is there a way to abort the request?
I've tried various different combinations of mapping the source and
different sinks, but they all do the same thing. Even attaching the
response.entity.dataBytes to a Sink.cancelled doesn't cancel upstream.
I'm using 1.0-RC4 from a few days ago, and have also upped
the max-content-length length in the config which may be part of the
problem, but to request a large file from S3 I couldn't work out any other
way. Still new to akka http and streams so if i'm going down the wrong
track then a point in the right direction would be great.
Cheers,
Will
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.