withoutRequestTimeout

Signature

def withoutRequestTimeout: Directive0

Description

This directive enables “late” (during request processing) control over the Request timeout feature in Akka HTTP.

It is not recommended to turn off request timeouts using this method as it is inherently racy and disabling request timeouts basically turns off the safety net against programming mistakes that it provides.

Warning

Please note that setting the timeout from within a directive is inherently racy (as the “point in time from which we’re measuring the timeout” is already in the past (the moment we started handling the request), so if the existing timeout already was triggered before your directive had the chance to change it, an timeout may still be logged.

For more information about various timeouts in Akka HTTP see Akka HTTP Timeouts.

Example

Scala
val route =
  path("timeout") {
    withoutRequestTimeout {
      val response: Future[String] = slowFuture() // very slow
      complete(response)
    }
  }

// no check as there is no time-out, the future would time out failing the test
Java
CompletionStage<String> slowFuture = new CompletableFuture<>();

final Route route = path("timeout", () ->
        withoutRequestTimeout(() -> {
            return completeOKWithFutureString(slowFuture); // very slow
        })
);

// test:
Boolean receivedReply = runRoute(system, materializer, route, "timeout").isPresent();
assert (!receivedReply); // timed-out
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.