playframework / playframework/play-ws

[2.5.3 Java] Not possible to set infinite WS request timeout with stream()

Open
#153 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:backlog
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
  1. Setting setRequestTimeout(-1)for a WSClient request and calling stream() should respect the timeout being infinite.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.