playframework / playframework/play-ws
[2.5.3 Java] Not possible to set infinite WS request timeout with stream()
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 224
- Forks
- 92
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 28
Description
Migrated from https://github.com/playframework/playframework/issues/6225
Play Version (2.5.x / etc)
2.5.3
API (Scala / Java / Neither / Both)
Java
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
Windows 8.1
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
Oracle JDK 1.8.0_92
Library Dependencies
None
Expected Behavior
- Setting
setRequestTimeout(-1)for a WSClient request and callingstream()should respect the timeout being infinite. - In the case of a timeout it should result in a Throwable being emitted to
whenComplete()
Actual Behavior
The following code reaches .whenComplete() without an exception after 120 seconds.
CompletionStage<StreamedResponse> events = ws.url("https://example.com/events")
.setMethod("GET")
.setHeader("Accept", "text/event-stream")
.setRequestTimeout(-1)
.stream();
events.thenCompose(res -> {
Source<ByteString, ?> responseBody = res.getBody();
return responseBody.via(Framing.delimiter(ByteString.fromString("\n"), Integer.MAX_VALUE, FramingTruncation.ALLOW)).map(ByteString::utf8String).runForeach(data -> logger.info(data), materializer);
}).whenComplete((done, throwable) -> {
if (throwable != null) {
logger.error(throwable.getMessage(), throwable);
}
logger.info("Done");
});
When setting the timeout to Integer.MAX_VALUE the call doesn't timeout after 120 seconds.
When changing to get() instead of stream() the infinite setting seems to be respected. However this doesn't help with Server-Sent Events and Akka Streams. Might be related to #4846.
Is there a workaround to get an infinite event-stream processing with Play 2.5?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Java WSClient stream() example with setRequestTimeout(-1), then compare its behavior with get() and the Integer.MAX_VALUE timeout case. Trace the stream() request-timeout handling and verify completion behavior for the Server-Sent Events example; done means an infinite timeout is respected and timeout failures reach whenComplete().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, scala
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100