play1 icon indicating copy to clipboard operation
play1 copied to clipboard

WS timeout has no effect if more than 60 seconds

Open daohodac opened this issue 8 years ago • 2 comments

see https://stackoverflow.com/q/45961070/1566975

response = WS.url(url).timeout("170s").postAsync() seems to fail: If your WS at url lasts more than 60 seconds and less than 170s, then response.onRedeem() call back is never called, response.isDone() is true and response.getOrNull() is null

I have attached a simple application that shows the problem (java8, play 1.4.4)

Execution logs:

10:07:06,542 INFO  ~ start JOB
10:07:06,552 INFO  ~ longTask called
10:08:06,776 INFO  ~ done onRedeem not called, isDone=true but response.get() is null
...
10:08:36,898 INFO  ~ done onRedeem not called, isDone=true but response.get() is null
10:08:36,898 ERROR ~ nothing under the sun after 90 seconds.

job-long-async.zip

daohodac avatar Aug 31 '17 12:08 daohodac

I can confirm this is still the case in 1.5.1. If you do a WS post (ie sync call)... a timeout exception is thrown after 60s, regardless how much longer you set the the timeout

jvosloo avatar Dec 07 '18 05:12 jvosloo

Oh. I know what the issue is. The underlying AsyncHttpClient exposes a request timeout method:

asyncHttpClient.preparePost(url).setRequestTimeout(120)

which is wrapped and exposed by Play and used like so:

WS.url(url).timeout("120s")

However, if you do a GET or POST that takes longer than 60 seconds to receive a response, you hit a read timeout, which defaults to 60 seconds.

This read timeout (amongst others) is a property which is configurable on the AsyncHttpClient via options, e.g.:

AsyncHttpClientConfigBean configBean = new AsyncHttpClientConfigBean().setRequestTimeout(120*1000).setReadTimeout(120*1000);
AsyncHttpClient asyncHttpClient = new AsyncHttpClient(configBean)

So, Play could expose another timeout method, in order to also control the read timeout:

WS.url(url).timeout("120s").readTimeout("120s")

but perhaps a cleaner, more extensible way would be to allow specifying various properties in application.conf, since there are various AsyncHttpClient properties that one could/may wish to configure. This apparently was already done in Play2 (see here: https://github.com/playframework/play-ws/issues/202#issuecomment-362222541)

What do you guys think?

jvosloo avatar Dec 21 '18 07:12 jvosloo