Railway docker app returns 502 bad gateway intermittently
s-kris
HOBBYOP

3 months ago

My nextjs app is running normally. But rarely, it returns 502 bad gateway errors when the frontend is hitting /api/<path-name> server routes. For example, an api endpoint that accepts PATCH req for saving a blog post. So, obviously this is a high traffic api route and 502 error is thrown for ONE request and the previous and after requests are executed successfully. But at the same time, a very idle api route also returns the same 502 error.

  1. There are no error logs in my app during that time

  2. There are no spikes in CPU usage during that time

  3. There are no spikes in memory usage during that time

I found a similar thread by another user: https://station.railway.com/questions/intermittent-502-gateway-errors-9540cb9e

$10 Bounty

10 Replies

Railway
BOT

3 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


3 months ago

Are you able to see the request in HTTP logs? It'll show you why the 502 happened

The majority of these cases are app-related, where your app didn't respond to our proxy's request in time resulting in an upstream timeout or connection closing prematurely. Unfortunately you'll need APM traces to debug why at the application level.


ray-chen

Are you able to see the request in HTTP logs? It'll show you why the 502 happenedThe majority of these cases are app-related, where your app didn't respond to our proxy's request in time resulting in an upstream timeout or connection closing prematurely. Unfortunately you'll need APM traces to debug why at the application level.

s-kris
HOBBYOP

3 months ago

  1. No 502 errors in the app logs

  2. I dont think thats the case but not sure. Any suggestions to confirm your hypothesis?


s-kris
HOBBYOP

3 months ago

People, I can confirm that this is happening only with railway. I deployed the exact same app to Vercel. I din't get such error.

Any resolution ?


3 months ago

App logs are different than HTTP logs. Would you mind checking the HTTP logs? Then we can see why it’s failing


s-kris
HOBBYOP

3 months ago

Ahh okay..

No, I couldn't find those except the logs I manually created from frontend via an additional request upon error!


3 months ago

The only ones I can see are these? Could you let me know which endpoints are failing with 502's and when/where?

Attachments


3 months ago

upstreamError: connection closed unexpectedly

So yea it looks like your app, for some reason, simply closed that connection. Why, unsure. We can look on our side but, something about that application under load is less than happy


s-kris
HOBBYOP

3 months ago

thats strange actually. some points to add more context:

  1. Not that high load

  2. This happens frequently on busy route (post auto-saving)

  3. But also happens on rarely used route as well

  4. exact same codebase on hetzner/vercel doesnt have this problem


s-kris
HOBBYOP

3 months ago

Actually, I just deployed a copy of the same app with zero traffic, but still I'm getting this error. Well, so I think this is as far as we can travel in railway.


Loading...