Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make the Promise timeout value configurable #1002

Closed
nraychaudhuri opened this Issue · 18 comments
@nraychaudhuri
Collaborator

Promise.timeout right now uses a default timeout value. It will be nice to get this value from the conf file.

@tavlima

+1

The timeout error happens mostly when stepping through debug, while testing.

@fosple

+1

@fosple

Still getting the error "java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]", if a promise takes too long to be fulfilled.

Please fix the TODO described in the following code segment and get the timeout value from the config file.
https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/libs/concurrent/Promise.scala#L274

private[play] lazy val defaultTimeout =
//TODO get it from conf
Duration(10000, TimeUnit.MILLISECONDS).toMillis

Thanks :)

@richdougherty

@fosple, can you please post the stack trace for that exception? There should be methods you can use that let you control the timeout value so you can avoid the error. In #1102 F.Promise.get() and F.Promise.timeout() were deprecated in favour of methods where the timeout value can be passed explicitly.

@fosple

I discovered the error only occurs if I use the "recover" function (http://www.playframework.com/documentation/api/2.1.0/java/play/libs/F.Promise.html#recover(play.libs.F.Function)):

java.lang.RuntimeException: java.util.concurrent.TimeoutException: Futures timed
 out after [10000 milliseconds]
        at play.libs.F$Promise$6.apply(F.java:401)
        at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future.scala:253
)
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249)
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67)
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:66)
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:82)
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
        at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72
)
        at akka.dispatch.BatchingExecutor$Batch.run(BatchingExecutor.scala:58)
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137)
        at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]
        at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96)
        at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58)
        at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
        at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
        at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:173)
        at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:2803)
        at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread.block
On(ThreadPoolBuilder.scala:171)
        at scala.concurrent.Await$.ready(package.scala:86)
        at play.api.libs.concurrent.PlayPromise.await(Promise.scala:134)
        at play.api.libs.concurrent.PlayPromise.await(Promise.scala:126)
        at play.api.libs.concurrent.PlayPromise.value1(Promise.scala:119)
        at play.libs.F$Promise.get(F.java:201)
        at controllers.MyApp.update(MyApp.java:316)

        at controllers.MyApp$2.apply(MyApp.java:48)
        at controllers.MyApp$2.apply(MyApp.java:44)
        at play.libs.F$Promise$PromiseActor.onReceive(F.java:420)
        at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
        at akka.actor.ActorCell.invoke(ActorCell.scala:386)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
        at akka.dispatch.Mailbox.run(Mailbox.scala:212)
        at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
@mcornejo

In testing, I had the same problem. After a lot of page visited I found this link: https://gist.github.com/traviskaufman/5210421/

These Gist give me some ideas, and it solves my problem, importing play.api.test.Helpers._ and then changing the timeout:

import play.api.test.Helpers._
await[Result](route(FakeRequest(POST, "/method")).get.asInstanceOf[AsyncResult].result, 100000)

-- Mario

@richdougherty

@fosple, this should be fixed in master with #1102. Are you testing against master?

@fosple

@richdougherty I'm using the master branch (#1133).

In fact #1102 really fixes the error. You were right! After upgrading to the master branch I forgot to add a timeout to one get() function. Sorry!

@richdougherty

@nraychaudhuri Are you happy that this is fixed? The timeout value can now be passed as an argument to the methods of F.Promise. There was also a 1 hour timeout buried inside the F.Promise implementation that has been removed.

@nraychaudhuri
Collaborator

Sounds good. Thx @richdougherty

@jroper jroper closed this
@angeloh

For anyone who see this thread, this is how I test on Play 2.2 to increase timeout value.

status(resp)(akka.util.Timeout(200000)) must equalTo(OK)

@kishykumar

Is this fix backported to Play 2.1 (specifically 2.1.1)?

@jroper
Owner

I don't think so.

@kishykumar

@jroper Which version did this fix go into? Is it fixed in 2.2.4?

@jroper
Owner

It was fixed in 2.2.0.

@bdmstyle

what is the conf to change default promise timeout? i'm not found.

@cchantep
Collaborator

@bdmstyle this issue is close. Please ask question on the Mailing List.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.