1

I am making a web service request that produces a Future. Like so (a simplified reproduction):

import play.api.libs.ws.WSClient
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._
class Service(wsClient: WSClient)(implicit ec: ExecutionContext) {
  def callWebService() = {
    val req: WSRequest = wsClient.url(...).withRequestTimeout(180 seconds)...
    val respFuture:Future[Response] = req.execute()
  }
}

The web service being invoked gets 180 seconds to respond before WSClient gives up.

This Service class' client now calls it as service.callWebService(). When the third party web service takes > 120 seconds, instead of waiting for 180 seconds, the future timesout at 120 seconds (java.util.concurrent.TimeoutException: Read timeout to localhost/127.0.0.1:8081 after 120000 ms thrown in application-akka.actor.default-dispatcher-3 thread).

Appreciate any pointers on how to increase the 120 seconds used by the default dispatcher to 180 seconds.

Note:

  1. The app uses Akka actors elsewhere. But there are no actors involved in this control flow.
  2. This post comes close but doesn't help.
Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
Ram
  • 865
  • 1
  • 8
  • 20

1 Answers1

3

Play WS includes a global request timeout, which defaults to 2 minutes.

Putting the following in your application's config (by default application.conf) should rectify things.

play.ws.timeout.request = 3 minutes
play.ws.timeout.idle = 3 minutes
Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
  • Setting that config didn't help (same TimeoutException at 2 mins.). – Ram Sep 22 '20 at 23:08
  • 2
    But setting play.ws.timeout.idle did resolve the issue. Thank you @Levi Ramsey. I would appreciate it if you include this in your answer for future reference. – Ram Sep 22 '20 at 23:24