1
votes

The documentation for akka-http explains that it is important to consume a request stream entirely since bytes that are not pulled will be interpreted as backpressure (https://doc.akka.io/docs/akka-http/current/implications-of-streaming-http-entity.html). When you know beforehand that the stream can be ignored you should use discardEntityBytes, or otherwise read it fully. There is also the option of closing the connection by attaching the stream to a Sink.cancelled.

My question is what happens when the stream fails.

  • Is the stream drained or is the connection closed? Or is it the responsibility of the implementation to recover from errors and either drain or close the connection? If so, what is a good code pattern for this?
  • Does it matter if a request is completed with a Future or if the response is streaming?
  • What if, instead of an unexpected failure, you determine half-way through the stream that the rest of the stream can be ignored. Is throwing an exception a good way of stopping stream processing?

Example completing with a future:

val route =
    post {
        extractDataBytes { data =>
            complete {
                data
                    .via(flow1)
                    .via(flow2) // say error happens here at some point
                    .runwWith(sink)
            }
        }
    }
1

1 Answers

0
votes

If the server connection is having problem then connection will be automatically closed.