502 error during cold boot?

msoutopico
HOBBYOP

a year 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

a year 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
HOBBYOP

a year ago

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


a year ago

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


a year ago

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


msoutopico
HOBBYOP

a year 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
HOBBYOP

a year 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
HOBBYOP

a year ago

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


a year ago

yeah im only talking about during runtime


msoutopico
HOBBYOP

a year ago

(rather than in the code of the application)


a year ago

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


msoutopico
HOBBYOP

a year ago

do you see why that is?


msoutopico
HOBBYOP

a year 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


a year 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
HOBBYOP

a year 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)


a year ago

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


msoutopico
HOBBYOP

a year ago

thanks, @Brody


msoutopico
HOBBYOP

a year ago

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


msoutopico
HOBBYOP

a year ago

(the client is another API deployed in Railway)


a year ago

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


msoutopico
HOBBYOP

a year ago

thanks, we'll try to achieve that


msoutopico
HOBBYOP

a year ago

any further tips that could help me achieve that?


msoutopico
HOBBYOP

a year ago

Thanks a lot for your help


msoutopico
HOBBYOP

a year ago

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


a year 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


a year ago

a reddit thread I saw recommended adjusting some configs


a year ago

other said to optimize dockerfile



msoutopico
HOBBYOP

a year ago

thanks, @Medim


a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...