# 502 Errors for POST requests

**URL:** <https://community.fly.io/t/502-errors-for-post-requests/2115>\
**Category:** Questions / Help\
**Created:** [August 6, 2021, 6:31am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115 "2021-08-06T06:31:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [August 6, 2021, 6:31am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/1 "2021-08-06T06:31:52Z")

</div>

Hi, I’ve been struggling to fix an issue I’m having when making a POST request to one of my apps.

When POST requests are made, I see this in the logs:

```auto
ams [error] error.code=2004 error.message="App connection idle" request.method="POST" request.url="https://gwil.garden/earthstar-api/v1/+gwilgarden.ooo/documents" request.id="01FCD20DR700PCG221BZ8APNQ5" response.status=502 

```

Or alternatively,

```auto
ams [error] error.code=2002 error.message="App connection problem" request.method="POST" request.url="https://gwil.garden/earthstar-api/v1/+gwilgarden.ooo/documents" request.id="01FCD21XWT44KD9TT79JS8NM72" response.status=502 

```

At first I thought this might be because I wasn’t returning the `Content-Length` header in the response, but that doesn’t seem to be it. I’m not really sure what the proxy is expecting. Would someone be able to help me diagnose?

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [August 7, 2021, 8:51am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/2 "2021-08-07T08:51:08Z")

</div>

I understand this isn’t very exciting, but I’d be _super_ grateful if someone from Fly could look up these error IDs and give me anymore information. Not understanding how to work with the proxy at times like this is the only thing stopping me from going all-in on Fly.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [August 7, 2021, 10:58am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/3 "2021-08-07T10:58:23Z")

</div>

Hello!

Sorry for the delay, we’ve had unrelated issues Yesterday. We usually respond pretty fast.

“App connection idle” means your app’s connection was idle (no bytes sent or received) for 60s and we closed it.

“App connection problem” can mean a few things, usually it means the connection (between your app and us) was broken, timed out connecting or closed at an unexpected time.

In this case, I see it timed out connecting. This would mean your app was unable to accept a connection within a few seconds. Connecting to an instance from the local host (which is what we do) should only ever take a few milliseconds. The timeout is set at 2 seconds if I recall correctly. This should be ample time, if your app cannot accept the connection within that time, something is very wrong.

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [September 9, 2021, 2:47pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/4 "2021-09-09T14:47:56Z")

</div>

@jerome I continue to be baffled by this. I think the proxy may be changing POST requests in some subtle way. The reason my app is returning ‘app connection problem’ is because it is choking when I call `request.json()` or `request.text()` inside my request handlers. I’ve tried putting them inside try/catch blocks, but they simply time out.

The same handlers work as expected when run locally. As soon as they’re up on Fly, things stop working. Does the proxy modify requests in any particular way? The bodies of my post requests are large, but not exceptionally so.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [September 9, 2021, 3:10pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/5 "2021-09-09T15:10:12Z")

</div>

The body should be passed as-is. Can you provide a `curl` request that reproduces the issue? So I can test this myself.

If this is sensitive information, please send via DM.

I looked at your current apps and couldn’t find much. There were connection timeouts attempting to reach your app. Looks like the event loop is blocked on your node app?

There’s a _tight_ timeout for connection to an app locally, mostly because it should take ~1-5ms to connect (the timeout is ~2 **seconds** iirc, roughly 400-2000x what it should normally take an app to accept a connection).

What kind of app is this? I assume node.js because of `request.text()` and `request.json()`. Are you manually accepting connections in a loop and something is holding it up from accepting more connections concurrently?

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [September 16, 2021, 10:29am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/6 "2021-09-16T10:29:48Z")

</div>

@jerome I was looking through a few new threads and some things caught my eye:

> [@Router errors 502 of POST requests "Undocumented"](https://community.fly.io/t/router-errors-502-of-post-requests-undocumented/2540/3):
>
> This error was the result of a failure to read the body from the request. We’re going to try to reproduce the problem. It could be a bug on our end, it might be something specific about how a browser is interacting with our proxy. It’s probably not your app.

My own error is caused by my app seemingly not being able to read the body of the request (via `request.text` or `request.json`).

> [@Slow S3 uploads for files larger than ~30KB](https://community.fly.io/t/slow-s3-uploads-for-files-larger-than-30kb/2553/1):
>
> When trying this out locally, upload latencies were reasonable in the sub ~100ms range. However, the same service when deployed to Fly results in uploads of over 3 _seconds_ for files that are larger than ~30KB. For smaller files the latencies are within the same ballpark as local dev, which makes this even more puzzling.

This error seems to happen for POST requests where the body is over 30kb in size. Below that, and the POST requests react as they are expected to.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [September 16, 2021, 12:40pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/7 "2021-09-16T12:40:18Z")

</div>

I just tried the `curl` you send me via DM again and it worked this time.

We did make some changes to how much data we’ll buffer. However, I’m pretty sure the initial limit of 1MiB wasn’t being hit by that request you provided. Our changes may have fixed it as a side effect 😕

@gwil are you still seeing issues? It could be specific regions.

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [September 17, 2021, 6:12am UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/8 "2021-09-17T06:12:22Z")

</div>

Still hangs for me, unfortunately. I think my app is only in the AMS region.

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [September 17, 2021, 12:23pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/9 "2021-09-17T12:23:02Z")

</div>

@gwil are you using the fly-replay feature? We’re seeing similar issues with uploads (as you’ve noticed) that use this feature.

It’s possible our proxy does _something_ to the content or headers. I’ve been troubleshooting this for the past 2 days and intend to figure it out Today 🙂

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [September 17, 2021, 1:14pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/10 "2021-09-17T13:14:06Z")

</div>

Not using the fly-replay feature either 😅

---

<div class="post-metadata">

**Author:** ![sudhir.j](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/sudhir.j/32/39775_2.png) [@sudhir.j](https://community.fly.io/u/sudhir.j)\
**Post date:** [September 17, 2021, 1:19pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/11 "2021-09-17T13:19:25Z")

</div>

@Jerome out of curiosity, though, what’s the buffer on the fly-replay feature? I don’t think the replay header is sent back to the browser, so how big a request can Fly hold and replay?

---

<div class="post-metadata">

**Author:** ![jerome](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jerome/32/17_2.png) [@jerome](https://community.fly.io/u/jerome)\
**Post date:** [September 17, 2021, 6:57pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/12 "2021-09-17T18:57:49Z")

</div>

@gwil we just figured out that if an app is writing too much to stdout, it can stall VMs. In our case, Rails was logging all the JSON body we were passing it and everything was locked up trying to write to stdout.

Is it possible your app is logging a lot to stdout / stderr when you get these large bodies?

> [@sudhir.j](#):
>
> @Jerome out of curiosity, though, what’s the buffer on the fly-replay feature? I don’t think the replay header is sent back to the browser, so how big a request can Fly hold and replay?

We’ve bumped it to 10MiB. It may or may not stay that way 😅

---

<div class="post-metadata">

**Author:** ![gwil](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/gwil/32/900_2.png) [@gwil](https://community.fly.io/u/gwil)\
**Post date:** [October 18, 2021, 1:40pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/13 "2021-10-18T13:40:31Z")

</div>

This ordeal is finally over, it seems Remix was doing something weird with requests and it has been fixed as of v0.19.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [October 18, 2021, 1:41pm UTC](https://community.fly.io/t/502-errors-for-post-requests/2115/14 "2021-10-18T13:41:30Z")

</div>

Wow that’s great news.
