[2.3.7-scala] WS.url("some url").withRequestTimeout(5000) timed out after 120s

217 views
Skip to first unread message

Simon

unread,
Dec 25, 2014, 9:22:23 AM12/25/14
to play-fr...@googlegroups.com
Hi,

Despite of setting the WS timeout to 5s, the time out happened after 120s, which is the default. I've seen this problem only once and cannot reproduce it. 

The exception was java.net.ConnectException: connection timed out

whereas the normal timeout exception would be java.util.concurrent.TimeoutException: Request timed out

Has anybody seen a similar behaviour? Should I rather wrap the call in a Future and handle timeout with Future.firstCompletedOf ?

thanks
Simon




Simon

unread,
Jan 3, 2015, 8:03:53 AM1/3/15
to play-fr...@googlegroups.com
update: apart from the aforementioned problem, the timeout behaviour is apparently quite lenient. Quite often the returned Future is completed much later than specified by "withRequestTimeout". To achieve correct timeout handling I ended up with something like the following:

val timeoutFuture = play.api.libs.concurrent.Promise.timeout(<timeout result>, <timeout>)
val wsFuture = WS.url(<url>).withRequestTimeout(<timeout>).get()
Future.firstCompletedOf(List(wsFuture, timeoutFuture))

does anybody know a better solution?

Will Sargent

unread,
Jan 5, 2015, 6:26:57 PM1/5/15
to play-fr...@googlegroups.com
Play WS is a wrapper around Ning's AsyncHttpClient to provide Scala like Futures and a more convenient API -- withRequestTimeout() calls out to the underlying config.setRequestTimeoutInMs, but doesn't do anything following.


Try to replicate this issue using AsyncHttpClient directly -- use 1.8.15 please, matching https://github.com/playframework/playframework/blob/2.3.x/framework/project/Dependencies.scala#L213 for Play 2.3.7 and then file an issue at https://github.com/AsyncHttpClient/async-http-client/issues if you can replicate it.  While AsyncHttpClient 1.9.x is out, it is not binary compatible with 1.8, so if they've fixed it but not backported it then it can't be used for 2.3.x.

Using Future.firstCompletedOf is something that I've seen others do in WS, notably Bjorn Hamel's Scala By The Bay talk:


Hope that helps.

Simon

unread,
Jan 8, 2015, 11:14:50 AM1/8/15
to play-fr...@googlegroups.com
after reboot this "lenience" disappeared, so I don't have any test scenario to reproduce this. Maybe some low level I/O glitch involved.
As this also happened in production, I'll stick with this firstCompletedOf workaround for now.

thanks
Simon

Reply all
Reply to author
Forward
0 new messages