akka / akka-http

The Streaming-first HTTP server/module of Akka
https://doc.akka.io/docs/akka-http
Other
1.34k stars 595 forks source link

2XX Early on Chunked responses #3809

Open notlaW opened 3 years ago

notlaW commented 3 years ago

We're seeing this warning in our logs:

Sending an 2xx 'early' response before end of request for http://localhost:8080/test received... Note that the connection will be closed after this response. Also, many clients will not read early responses! Consider only issuing this response after the request data has been completely read!

We think it might have to do with the handling chunked requests. Here is a very basic example:

  val route =
    post {
      complete(StatusCodes.OK)
    }
}
curl --request POST \
  --url http://localhost:8080/test \
  --header 'Content-Type: application/json' \
  --header 'Transfer-Encoding: chunked' \
  --data '{
  "data": "small data"
}

OR

When the request includes a large payload (130kb+)

curl --request POST \
  --url http://localhost:8080/test \
  --header 'Content-Type: application/json' \
  --data '{
  "data": "{130kb_of_data}"
}'

Will yield the same warning.

This was discovered in the logs of a service that acts as a pass through proxy. The warning indicates that we are responding BACK to the client before the LAST chunk is read or marked as processed by the service. Due to it being a proxy we do not have any intention of reading in all the bytes into memory, and are hoping to shed some more light as to why we are seeing this warning.

jrudolph commented 3 years ago

Thanks for the question, @notlaW.

val route = post { complete(StatusCodes.OK) } }

You are not reading the request body here, so the warning is expected.

This was discovered in the logs of a service that acts as a pass through proxy. The warning indicates that we are responding BACK to the client before the LAST chunk is read or marked as processed by the service. Due to it being a proxy we do not have any intention of reading in all the bytes into memory, and are hoping to shed some more light as to why we are seeing this warning.

In that case, it depends on the proxy implementation and also on the backend behavior. You will see the warning either if you don't pass all request body data to the backend, or if the backend sends back a response before all request body data has been propagated by the proxy.