R
Railway9mo ago
leniac

Flask server failing when load increases

I've deployed a flask server and it works totally fine if I test it on a dev Vercel deployment, but as soon as I switch the prod backend to the railway flask server and start getting high traffic, I get this weird error over and over. Definitely a traffic thing because it even works for the first few seconds that I deploy, but quickyl get CORS error, presumably because the server can't send back headers.
2024-02-25 18:05:24 +0000] [11] [ERROR] Socket error processing request.
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 133, in handle
req = next(parser)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 186, in __init__
super().__init__(cfg, unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 53, in __init__
unused = self.parse(self.unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 235, in parse
self.headers = self.parse_headers(data[:idx])
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 73, in parse_headers
remote_addr = self.unreader.sock.getpeername()
OSError: [Errno 107] Transport endpoint is not connected
2024-02-25 18:05:24 +0000] [11] [ERROR] Socket error processing request.
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 133, in handle
req = next(parser)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 186, in __init__
super().__init__(cfg, unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 53, in __init__
unused = self.parse(self.unreader)
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 235, in parse
self.headers = self.parse_headers(data[:idx])
File "/opt/venv/lib/python3.8/site-packages/gunicorn/http/message.py", line 73, in parse_headers
remote_addr = self.unreader.sock.getpeername()
OSError: [Errno 107] Transport endpoint is not connected
Solution:
i would try with a single replica but with more workers and threads
Jump to solution
11 Replies
Percy
Percy9mo ago
Project ID: ce32fe10-d6e2-48b8-97c2-1f14b564dc39
leniac
leniac9mo ago
ce32fe10-d6e2-48b8-97c2-1f14b564dc39
Brody
Brody9mo ago
have you tried increasing the workers and threads?
leniac
leniac9mo ago
how do I do that?
Brody
Brody9mo ago
have a read of gunicorns docs, they provide flags to set the number of workers and threads gunicorn will use
leniac
leniac9mo ago
upping the number of replicas seems to have done the trick!
Solution
Brody
Brody9mo ago
i would try with a single replica but with more workers and threads
leniac
leniac9mo ago
railway runs the flask server for me though, would you suggest switching to a docker container so I can actually set these parameters?
Brody
Brody9mo ago
railway does not run the server for you, you are in full control of whats ran at all times most python users have their start commands defined in a Procfile
leniac
leniac9mo ago
ohh got it thanks performance is great! thanks for saving our app!
Brody
Brody9mo ago
no problem!
Want results from more Discord servers?
Add your server