502 error during cold boot?

msoutopico
PROOP

2 years ago

Project ID: 483187d7-a9d4-4961-b10f-f2804b57d52b

The "serverless" (formerly "sleep" right?) is active in my fastAPI application in Railway. There have been a few occasions this week when a request was not received (or least I didn't see a trace of it in the logs). The container started and then closed, but the request was not queued as far as I can see.

I would prefer not to disable the sleep/serverless feature, so I am considering a recursive call to a dummy /awake endpoint that would take place prior to the actual request to "awaken" the app, and would iterate a predetermined numbered of times (say, 5) while it gets status code 502. Would you say this is a good approach to avoid the problem?

Or are you aware of any issues on your end that might be related?

Thanks, Manuel

<#1006629907067064482>

Solved

29 Replies

2 years ago

how long does your app take to boot? if it takes longer than 10 seconds we will cancel the incoming request and return our 502 page instead


msoutopico
PROOP

2 years ago

Yes, that's what I have seen, it's possible that it takes longer than 10 seconds.


2 years ago

then yeah theres nothing we can do about that from our side, your app would have to start faster


2 years ago

are you doing something at boot that takes a long time?


msoutopico
PROOP

2 years ago

Every time the app is (re) deployed, there are a few dependencies that need to be downloaded and installed, but I don't consider that as part of the booting.


msoutopico
PROOP

2 years ago

Although if by "boot" you mean start after sleep (you probably do), I don't think there's anything in particular in the booting that takes long. The action of the app take long but I don't consider them as part of the booting.


msoutopico
PROOP

2 years ago

Could there be something incorrect in the app's settings?


2 years ago

yeah im only talking about during runtime


msoutopico
PROOP

2 years ago

(rather than in the code of the application)


2 years ago

yeah i can see from the logs its taking a long time for your application to start


msoutopico
PROOP

2 years ago

do you see why that is?


msoutopico
PROOP

2 years ago

I know the processing may take up to 1 min (from the moment the API gets the request until it sends a response), but I'm not aware why it could take long to start


2 years ago

no im sorry but i have no way to answer that, we do not have any observability into what your code is / is not doing


msoutopico
PROOP

2 years ago

so you are saying that the fact it takes long to start comes from the code itself, right? (not the settings of the app)


2 years ago

correct, this is an issue at the application level, and not at the platform level


msoutopico
PROOP

2 years ago

thanks, @Brody


msoutopico
PROOP

2 years ago

what do you think about my hacky workaround (having the client send recursive call to that /awake)


msoutopico
PROOP

2 years ago

(the client is another API deployed in Railway)


2 years ago

i think it would be best to work towards having your app start faster


msoutopico
PROOP

2 years ago

thanks, we'll try to achieve that


msoutopico
PROOP

2 years ago

any further tips that could help me achieve that?


msoutopico
PROOP

2 years ago

Thanks a lot for your help


msoutopico
PROOP

2 years ago

If you have any other tips about how I can track what is causing the problem, they would be appreciated


2 years ago

with a quick google search u can see that fastapi has some troubles with cold starts so you aren't the only one with these issues


2 years ago

a reddit thread I saw recommended adjusting some configs


2 years ago

other said to optimize dockerfile



msoutopico
PROOP

2 years ago

thanks, @Medim


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...