R
Railway6mo ago
Bartek

App sleeping returns 502 Bad Gateway when the app is being resumed

After that error occurs, when I refresh the page again the app responds normally and there is nothing in logs. I have the new runtime enabled and the new proxy.
No description
Solution:
you have a few options - - figure out why your app accepts a tcp connection but not an http request and remedy that. - stick caddy in front of the service to retry connections on non-200 status code responses. - keep app sleeping disabled....
Jump to solution
21 Replies
Percy
Percy6mo ago
Project ID: N/A
Bartek
BartekOP6mo ago
N/A I would expect it to wait for the container to start up again and then display the page instead of just responding with a bad gateway while the container is still being started
Brody
Brody5mo ago
I assume that means the container did start but your app didn't respond in time do you run migrations in your start command?
Bartek
BartekOP5mo ago
I do not
Brody
Brody5mo ago
what kind of app is this?
Bartek
BartekOP5mo ago
nextjs site which is not connected to any database or anything just a static website
Brody
Brody5mo ago
what's your start command?
Bartek
BartekOP5mo ago
Before the app starts railway responds did not change it not using custom so its most likely just npm run start
Brody
Brody5mo ago
are you using a health check
Bartek
BartekOP5mo ago
i am not
Brody
Brody5mo ago
go ahead and implement that
Bartek
BartekOP5mo ago
just putting a / will work?
Brody
Brody5mo ago
if it's a static site, yeah just the root path is fine I can't remember if railway checks the health check when resuming a slept app, but it's good to have either way
Bartek
BartekOP5mo ago
Yeah it doesnt work Before Starting Container appears in logs railway responds with a 502 i mean at the same time^
Brody
Brody5mo ago
okay, i asked the team about this and will get back to you when i have more information
Bartek
BartekOP5mo ago
Thanks
Brody
Brody5mo ago
did you need an immediate solution? because i may have something you can try
Bartek
BartekOP5mo ago
No I will just disable app sleeping in the meantime Lol
Brody
Brody5mo ago
sounds good! got an answer back, this basically means your app was not able to answer the initial http request fast enough. when there is an incoming request for a slept service, the sleeping service is started and is tcp probed every 30ms for a maximum of 10 seconds, once a prob is successful the http request gets sent to your app, if you app doesn't respond then you will see a railway error page
Solution
Brody
Brody5mo ago
you have a few options - - figure out why your app accepts a tcp connection but not an http request and remedy that. - stick caddy in front of the service to retry connections on non-200 status code responses. - keep app sleeping disabled.
Brody
Brody5d ago
We've resolved an issue where apps with longer startup times were showing 502 errors. Apps now have up to 10 seconds to start accepting traffic, thus preventing these error pages from appearing. You will need to trigger a deployment so that the changes we have made take effect. cc @Bartek
Want results from more Discord servers?
Add your server