spray.can.client.request-timeout versus sendReceive's timeout

429 views
Skip to first unread message

Kevin Meredith

unread,
Mar 20, 2016, 8:05:21 PM3/20/16
to spray.io User List
My "system" consists of:

client <-- HTTP --> web service 

where the client uses spray-client.

I kept seeing the following same error:

Failed due to POST request to /path/to/my/route timed out


Note that, at this time, that I had not overridden any `spray.can.client` config values.


Having observed that the HTTP request had succeeded, i.e. checking the UI of the web service, but the client reported failure, it seemed that I needed to increase my client-side timeout.


So, I updated my `application.conf`:


spray.can.client {
request-timeout = 2 minutes
idle-timeout = 130 seconds
}

However, in my main method, when I block:

val result = Await.result(future, 2.minutes)

I observed the following error:

Failed due to Ask timed out on [Actor[akka://default/user/IO-HTTP#...]] after [60000 ms]


This error confused me since I had expected the spray.can.client settings to have overridden the 20 s default:

# If a request hasn't been responded to after the time period set here
    # a `spray.http.Timedout` message will be sent to the timeout handler.
    # Set to `infinite` to completely disable request timeouts.
    request-timeout = 20 s
Finally, I saw a spray maintainer comment in this StackOverflow question - akka timeout when using spray client for multiple request.

That's the timeout of sendReceive. See github.com/spray/spray/blob/master/spray-client/src/main/scala/… You can adapt it by providing another implicit 
Timeout in scope. E.g. implicit val timeout = Timeout(120.seconds)

So, at this point, I'm confused as to what config value or implicit that I need to add to force this client to wait 120 seconds before failing the request.

Kevin Meredith

unread,
Mar 26, 2016, 3:37:42 PM3/26/16
to spray.io User List
During my own testing, I observed, per the following setup:

POSTMAN client <-- HTTP --> spray web service 


4-minute `implicit` time-out with 2 minute `application.conf` time-out

I had created an implicit Timeout of 4 minutes:

implicit val timeout: Timeout = Timeout(4.minutes)


val pipeline: HttpRequest => Future[HttpResponse] = sendReceive

with `src/main/resources/application.conf` values of:

 spray.can.client {
   request-timeout = 2 minutes
   idle-timeout    = 130 seconds
 }

 spray.can.server {
   request-timeout = 2 minutes
   idle-timeout    = 130 seconds
 }

When sending an HTTP Request from POSTMAN to my spray web service, an HTTP Request that took 3 minutes to reply resulted in:

  "The server was not able to produce a timely response to your request."

At this point, I speculated that my application.conf values were too blame. 

Using 4-minute `implicit` Timeout with `application.conf` time-out too 

So, keeping my 4 minute implicit Timeout, I increased my application.conf values:

 spray.can.client {
   request-timeout = 4 minutes
   idle-timeout       = 250 seconds
 }

 spray.can.server {
   request-timeout = 4 minutes
   idle-timeout       = 250 seconds
 }

Re-sending that same request via POSTMAN, I received an HTTP-200 - success.

Setting 4 minute time-out in `application.conf` only

Finally, re-sending the request that takes 3 minutes to complete, I received the following response in POSTMAN:

akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://null-system/user/IO-HTTP#-734594501]] after [60000 ms] 

In short, it appears to me, via this example, that both the `implicit val Timeout` and `application.conf` time-out need to be set.
Reply all
Reply to author
Forward
0 new messages