R
Railwayβ€’6mo ago
Mike πŸ¦‘

FastAPI + Hypercorn dropping connection after 60 seconds

Hey I'm running a FastAPI with hypercorn. Everything was fine last month, now encountering server dropping requests after 60 seconds. Remote end closed connection without response keep-alive is 120 seconds with hypercorn. runs as expected locally but disconnects on railway after 60 seconds. any thoughts?
31 Replies
Percy
Percyβ€’6mo ago
Project ID: a321c36a-8bf1-4eba-b44d-d026fff6a67b
Brody
Brodyβ€’6mo ago
is this a post request?
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
a321c36a-8bf1-4eba-b44d-d026fff6a67b Yep
Brody
Brodyβ€’6mo ago
just tested a long lived post request, got well over 60 seconds, this would be a config issue with fastapi/hypercorn. does hypercorn provide a way to configure the max request time? (keep-alive isnt the same thing)
Brody
Brodyβ€’6mo ago
No description
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
damn, okay thanks for testing so strange....i could run them last time i tested and when i run local, post reqs are fine
Brody
Brodyβ€’6mo ago
definitely strange but not a railway issue as shown above, if you would like to test yourself, post to https://utilities.up.railway.app/upload?slimit=0.25 i will note that railway does have a 5 minute max request time for post requests.
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
ah okay, thanks Brody πŸ™ i'll try a fresh deploy from scratch
Brody
Brodyβ€’6mo ago
without any config changes i dont know how much that would do to solve this, but the good 'ol reboot cant hurt
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
yep fresh install has same problem - must be config 🫠
Brody
Brodyβ€’6mo ago
maybe hypercorn changed some defaults?
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
hmm now even tried migrating to gunicorn and uvicorn and still same issue... this feels like an SSL / Railway issue. Still works fine on localhost
Brody
Brodyβ€’6mo ago
im sorry but if it was a railway issue i would be able to replicate it here
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
would it have something to do with nginx? can i change the config on railway? all other settings look fine in hypercorn :/
Brody
Brodyβ€’6mo ago
railway doesnt use nginx
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
what does it use? i've tried everything possible now - gunicorn, uvicorn, hypercorn. all with the same error. 60 second connection drops apparently default nginx SSL Timeout is 60 seconds thats why i suspected all three work on localhost only when i deploy, it gives me the error fastapi keeps running even when the connection drops, so i feel it has to be this right?
Brody
Brodyβ€’6mo ago
they currently use envoy and they have set the timeout to 5 minutes, envoy is not end user configurable. but once again, the issue is not with railway, please try posting to that endpoint yourself while I have provided clear proof that the timeout is not 60 seconds, i have asked a team member to confirm the timeout, they confirmed for me that it is 5 minutes
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
can you share the code that you're using? I have now deployed servers with: - flask + gunicorn - (uvicorn | gunicorn | hypercorn) + fastapi - expressJS ALL have a POST timeout at 60 seconds i'm so lost
Brody
Brodyβ€’6mo ago
my code was in go are you sure this isn't a client limitation instead? how are you testing these timeouts
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
hmm might be.... testing with python requests
Brody
Brodyβ€’6mo ago
I tested with the insomnia desktop app
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
requests.post(url, headers=headers, data=json.dumps(data))
Brody
Brodyβ€’6mo ago
how much json are you sending if it's taking more than 60 seconds lol
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
GitHub
nixpacks/src/providers/staticfile.rs at 33bbd27224604ae882b66895dfa...
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
i'm just calling sleep(65) on my end to test
Brody
Brodyβ€’6mo ago
that has nothing to do with the python or node providers
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
some requests in prod take longer than 60 seconds timeouts look fine for both locally might try deploy with another cloud provider to test...
Brody
Brodyβ€’6mo ago
I don't know what to tell you here, I have proven that it isn't a limitation with Railway, and a railway team member has told me directly that it's 5 minutes I can show you that message if you'd like?
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
okay thanks Brody nah its fine thanks for trying to help πŸ™
Brody
Brodyβ€’6mo ago
no problem!
Mike πŸ¦‘
Mike πŸ¦‘β€’6mo ago
Solved! Something in the nix-built dockerfiles is dropping posts after 60 seconds. Deployed via my own dockerfile and we’re cooking πŸ‘¨β€πŸ³ thanks for your help again Brody!