Spray-Client HTTP Request not timing out as expected.

61 views
Skip to first unread message

V

unread,
Feb 18, 2015, 12:20:49 PM2/18/15
to spray...@googlegroups.com
Hi,

I can't seem to get the RequestTimeoutException thrown.

My app conf has:

spray.can.client.request-timeout = 10 ms

I have an Actor which has the following:

implicit val timeout: Timeout = Timeout(60.seconds)
val url = //...create url
val f: Future[HttpResponse] = IO(Http).ask(HttpRequest(GET, Uri(url))).mapTo[HttpResponse]

f onComplete {
  case Success(response) =>
    response.status match {
      case StatusCodes.OK =>
        logger.info("ok")

      case StatusCodes.NotFound =>
        logger.error("not found")

      case _ =>
        logger.error("other")
    }
  case Failure(exception) =>
    logger.error("Request Timed out")
}

This could be entirely my misunderstanding, but given the Future timeout is 60 seconds, and the Spray-Client Request Timeout is 10 milliseconds, I would have expected to have seen "Request Timed Out" in my log. Instead I see "ok".

The code gets an image, something that always takes longer than 10 ms to respond, can any one tell me what I've done wrong?


Thanks!

Age Mooij

unread,
Feb 18, 2015, 1:37:48 PM2/18/15
to spray...@googlegroups.com
AFAIK the request timeout will only get activated when no bytes at all get sent over the response connection during the configured time period. I would guess that the server serving your image does in fact respond with the first byte(s) within 10 ms. However long it takes to deliver the rest of the bytes is not important in this case. 

Try delaying the server or setting the request timeout even lower.

Age


--
You received this message because you are subscribed to the Google Groups "spray.io User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/e96723da-26eb-4496-a041-841218c12900%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mathias Doenitz

unread,
Feb 19, 2015, 3:50:48 AM2/19/15
to spray...@googlegroups.com
This is the setting that you might have been missing:
https://github.com/spray/spray/blob/master/spray-can/src/main/resources/reference.conf#L214

By default the spray-can layer is not prepared to deal with timeout granularities in the range of 10s of milliseconds.
spray-can is designed to support a very large number of concurrent connections and timeout checking introduces a per-connection cost.
Since normally timeouts are measured in seconds rather than milliseconds the default granularity is 250ms.

If you set this to something like 10ms you should see your timeout being triggered.

Cheers,
Mathias

---
mat...@spray.io
http://spray.io

V

unread,
Feb 23, 2015, 8:30:25 AM2/23/15
to spray...@googlegroups.com
Thanks Mathias, that was the missing property I hadn't set. All operating as expected.
Reply all
Reply to author
Forward
0 new messages