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.
There are no error logs in my app during that time
There are no spikes in CPU usage during that time
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 Replies
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.
3 months ago
No 502 errors in the app logs
I dont think thats the case but not sure. Any suggestions to confirm your hypothesis?
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
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
3 months ago
thats strange actually. some points to add more context:
Not that high load
This happens frequently on busy route (post auto-saving)
But also happens on rarely used route as well
exact same codebase on hetzner/vercel doesnt have this problem
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.