akka / akka/akka-http

Request timeouts not logged accurately

Open
#607 5 comments 0 reactions 0 assignees View on GitHub
1 - triaged t:core t:docs t:routing t:server
Dominant language
Scala
Stars
1.4k
Forks
584
Avg merge
14h 33m
Merged PRs (30d)
24

Description

Hello akka-http team, I've got a few questions about configuring request timeouts.

Our current route setup looks something like this:

```
implicit def system: ActorSystem
implicit def materializer: ActorMaterializer
implicit def timeout: Timeout

val baseRoutes: Route =
accessLog(logger)(system.dispatcher, timeout, materializer) {
withRequestTimeout(20.seconds, request => timeoutResponse) {
(handleExceptions(exceptionHandler) & handleRejections(rj)) {
getf {
val x = Future { Thread.sleep(25000); "ok" }
complete(x)
} ~
...
```

We have a piece of logging middleware, `accessLog` that attempts to catch all returned responses and logs them. We've also added a `withRequestTimeout` directive to ensure all requests are returned within a 20 second window with a custom response.

The problem is when I hit an endpoint that takes long enough to timeout; akka will return the response defined in `timeoutResponse`, but will log it as a successful API request:

`[02/Dec/2016:21:31:41 -0000] "GET http://localhost:8080/ HTTP/1.1" User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36 200 2 25053ms`

Right now, it appears everything worked fine, even though the response time of this endpoint exceeded the defined timeout. Is there any way I can increase the accuracy of this log?

Contributor guide

Open the contributing guide

Research direction

Reproduce the route using accessLog, withRequestTimeout, timeoutResponse, and the delayed Future shown in the report. Trace how the timeout response reaches the logging middleware and compare the logged status with the configured response. Done means timed-out requests are logged accurately rather than as successful requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, backend, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.