Sunil
Sunil

Reputation: 70

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?

Upvotes: 0

Views: 439

Answers (1)

Pritish
Pritish

Reputation: 591

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.

Upvotes: 1

Related Questions