Intermittent 502 errors from proxy rewrite and long load times

I have a very basic static web page that is set up to proxy requests through rewrite. The toml looks something like this:

from = “/api/infer/base64”
to = “
status = 200
force = true
headers = {X-From = “Netlify”}

When working with this API locally (vite config to also proxy my local web server to that IP/route), everything responds fast and there never are any issues.

However, when I deployed to Netlify the static assets, I am sometimes seeing long requests and even 502s.

Here are a few request IDs:

x-nf-request-id: 01GCM4R9QV94NTMWVHZ3F5RPAA (took ~16s)
x-nf-request-id: 01GCM4ZG5KD60N1XBR9W37YQK3 (error 502 after 700ms)

Things do work about ~75% of the time, but what gives?

I can see the same error for both those IDs in our logs:

msg="unable to buffer request body" error="request body too large"

Are you using that for a file upload? Could you let us know the size of the files you’re trying to upload?

Kind of. The post body has potential large base64 strings of images.

How come sometimes the request errors and sometimes not? I am sending the same payload. Is it hitting a load balancer and certain proxy servers have a different limit on size?

I’d assume the limit to be same on all nodes. Do you know the length of the body though? I’d like to try sending a similar string myself to test.

The image is about 7.7MB but I’m unsure how much that is in base64 string and compressed. Here is a sample image

You can go to my app assuming you can look up the URL and just upload that file. The network tab can get you the exact query

Thanks! While I couldn’t use your image as Discourse compressed it, I tried to use another large image on a test site and it appears to be an issue. I wasn’t aware of any such limits yet, so I’ve escalated this to the devs to confirm about this.

We’d let you know as we have more information.

Hey @ssesfahani,

We heard back from the engineers, and it turns out, we have a 8 MB upload limit for performance reasons. You only get the error sometimes, because we are only buffering the body in specific situations.

1 Like