Handling request timeouts with client side http

603 views
Skip to first unread message

Chris Baxter

unread,
Jun 4, 2015, 8:47:46 AM6/4/15
to akka...@googlegroups.com
I know in Spray that had a request-timeout setting that could be used to control when to timeout a request that has sent the request but has yet to receive a response within a specified timeframe.  I don't see this setting anywhere in Akka Http.  For a single request, I can handle this by adding takeWithin to my stream processing like so:

  val poolClientFlow = Http().cachedHostConnectionPool[Int]("localhost", 9200)
  val responseFuture: Future[(Try[HttpResponse], Int)] =
    Source.single(HttpRequest(uri = "/foo/bar/16") -> 42)
      .via(poolClientFlow)
      .takeWithin(5 seconds)
      .runWith(Sink.head)

In this case, the Future would be failed with a NoSuchElementException which I suppose I can interpret to mean the timeout occurred.  Is there a better way to do this?  What happens to the underlying connection from the pool in this case?  If it was really and truly hung (as opposed to just being a little late with the response) I would want it closed.  Is this kind of stuff possible?

Konrad Malawski

unread,
Jun 26, 2015, 6:41:32 AM6/26/15
to Akka User List
Hi Chris,
I think the feature you're after is described in the ticket:

Also see here for an in depth response about this issue: 

--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,
Konrad 'ktoso' Malawski
Reply all
Reply to author
Forward
0 new messages