Repository navigation
Description
Title: 413 error payload too large when use nginx and envoy together when posting a file that is bigger than 1Mb. If I post the file to nginx or envoy by itself, the problem doesn't exist
Description:
I deployed the simple app from https://github.com/rayh0001/gs-spring-boot-docker to my k8s cluster in ibm cloud. I also have istio running in my k9s cluster.
When i send the curl command to the service with a post of a file over 1MB, I'm getting 413.
$ curl -svo /dev/null -F '[email protected]' mycluster.us-east.containers.mybluemix.net/scan -H 'transactionId: 11111' -H 'Cache-Control: no-cache'
* Trying 169.60.83.14...
* TCP_NODELAY set
* Connected to mycluster.us-east.containers.mybluemix.net (169.60.83.14) port 80 (#0)
> POST /scan HTTP/1.1
> Host: mycluster.us-east.containers.mybluemix.net
> User-Agent: curl/7.54.0
> Accept: */*
> transactionId: 11111
> Cache-Control: no-cache
> Content-Length: 1449466
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------c65bbc05407833b1
>
< HTTP/1.1 100 Continue
} [154 bytes data]
< HTTP/1.1 413 Payload Too Large
< Date: Sat, 24 Mar 2018 00:32:08 GMT
< Content-Type: text/plain
< Content-Length: 17
< Connection: keep-alive
* HTTP error before end of send, stop sending
<
{ [17 bytes data]
* Closing connection 0
Chatted with @PiotrSikora who suggested to tweak per_connection_buffer_limit_bytes to workaround this issue. I developed a pilot webhook (https://github.com/linsun/istioluawebhook) and the issue is resolved when the webhook is running.
I wanted to open this issue to see if this is something envoy can fix, e.g. Envoy should slow-down reading from the wire once it exceeds soft watermark. As a user, I'd prefer this is handled dynamically by envoy.
- Logs *:
[2018-03-13 01:39:55.026][350][debug][http] external/envoy/source/common/http/conn_manager_impl.cc:1310] [C36][S17322680420845703538] request data too large watermark exceeded
Activity
linsun commentedon Mar 28, 2018
cc @cmluciano
PiotrSikora commentedon Mar 28, 2018
FWIW, I spent some time looking into this last week, but I couldn't replicate it myself, even with something as ridiculous as
per_connection_buffer_limit_bytes: 1024.cc @alyssawilk
mattklein123 commentedon Mar 28, 2018
By default Envoy is fully streaming and will apply back pressure. Most likely there is some filter that is buffering somewhere. Can you provide your full configuration? Are any of your installed filters buffering the request?
alyssawilk commentedon Mar 28, 2018
Yep, the http connection manager only sends a 413 for non-streaming (buffering) filters so I suspect you've got one somewhere in your config. Well or we have a bug, but if you post the config we can take a look :-)
linsun commentedon Mar 28, 2018
@mattklein123 @alyssawilk thanks for your comment. Just to make sure - are you asking for envoy configuration on the istio-ingress in this case?
kyessenov commentedon Mar 28, 2018
kyessenov commentedon Mar 28, 2018
alyssawilk commentedon Mar 28, 2018
Yeah, so if you never want to 413 you have to either only use streaming filters, or configure infinite buffering (which opens you up to OOM attacks if you don't control the downstream traffic). We don't currently have anything which will clamp down on memory on a global level, only the per-connection limits.
linsun commentedon Mar 28, 2018
BTW, here is my istio ingress envoy config for listeners (with the newly added per_connection_buffer_limit_bytes by me via pilot webhook). I'm not seeing mixer filter buffer in there. @kyessenov I assume the code you pointed earlier will overwrite the filter in the config below? Do we know why mixer does buffer? is it to improve performance? if so, what would be our recommendation for istio users when they need to load relatively large files to their services....
alyssawilk commentedon Mar 28, 2018
is all you need for 413s, given the line of code @kyessenov linked. Basically any time state_ == Calling you buffer limited data instead of pushing back on downstream via H2 flow control / TCP window limits.
I can't speak to why that decision was made - it looks like the filter shouldn't pass data upstream until the check is complete but if the body doesn't need to be completely read for the check to proceed you might just be able to change the return at :136 and solve your problem. If there's documentation we can make more clear for future filters do let us know, otherwise we'll probably close this off a working as intended.
mandarjog commentedon Mar 28, 2018
@qiwzhang is there a reason to buffer when
state_ == Callingmandarjog commentedon Mar 28, 2018
cc @lizan
kyessenov commentedon Mar 28, 2018
mattklein123 commentedon Mar 28, 2018
You can also write the filter such that it only buffers up till the decision is made, and then starts streaming. That is how our internal Lyft auth filters work, as well as the ratelimit filter in the public repo. But you will need to increase the buffer level to some amount that is mostly safe to account for service latency.
lizan commentedon Mar 28, 2018
It is likely mixer filter is buffering the data, filed https://github.com/istio/proxy/issues/1315, it do only buffers up till the decision is made but it can still buffers too much.
linsun commentedon Mar 28, 2018
thank you @lizan @mattklein123 @PiotrSikora @kyessenov @mandarjog @cmluciano @alyssawilk -- i appreciate everyone look into this prob and try to propose a solution. I agree this issue can be closed in envoy as we are not expecting any action from envoy at the moment.
alyssawilk commentedon Mar 28, 2018
Leaving this closed but commenting for the record, if you change the return code you're not telling Envoy "do not buffer the data" you're telling Envoy "I can make forward progress without the entire request body being buffered"
A streaming filter will result in the current data will be buffered, but Envoy will push back (again via TCP window or H2 flow control) and ask downstream to stop proxying data. Envoy will buffer any and all data until that flow control kicks in. The "Buffering" on return indicates the filter must buffer the full request body before it makes a decision (like it needs to do some checksum on the request body before it can send headers on) so will not be able to make forward progress if downstream stops spooling data. Does that make sense?
lizan commentedon Mar 28, 2018
Thanks for explanation @alyssawilk, yeah that matches my understand. Before the flow control support for filters, we didn't have
StopIterationAndWatermark, soStopIterationAndBufferwas the only option.I feel we need kind of release notes for filter (or extension) developers to document this kind of C++ API changes (in
include/). While I regularly monitor diffs ofinclude/but somehow I missed #1417 to migrate istio filters. I will open another issue for this.