Search code examples
scalaakkaakka-httpconcurrent.futures

Future getting timed out on getting the akka http response


m new to the concept of Futures and i'm getting a Future timed out exception when i'm trying to retrieve a HTTPResponse.

val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = sampleUrl).withHeaders(Authorization(validCredentials)))
    val timeout = 2.seconds
    responseFuture.flatMap { resp => resp.entity.toStrict(timeout) }.map { strictEntity => strictEntity.data.utf8String }

It works as intended for sometime on the cluster where its hosted and crashes, when I check the logs. It says Future timed out after 2 seconds. how do I correct this?


Solution

  • It seems like your sampleUrl is not consistently responding within 2 seconds. By default HTTP clients wait for up to 60 seconds before they fail to receive a response. Perhaps, you could set the Future timeout on the similar lines at 60 seconds.