Search code examples
scalaplayframeworkplay-ws

Play WS request times out sooner than withRequestTimeout


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.

Solution

  • 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