Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket error processing request with flask, gunicorn, docker and azure

Running a python flask app with gunicorn. When I spin up the docker image locally everything is fine, but when I run the docker image on azure with kubernetes, I get this OSError. The request is fine, but get an error in the log.

Does anyone now what is happening?

10.242.0.1 - - [31/Jul/2018:15:11:04 +0000] "GET /api/evaluation HTTP/1.1" 200 14343  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
[2018-07-31 15:11:05 +0000] [10] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 134, in handle
    req = six.next(parser)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/parser.py", line 41, in __next__
    self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 181, in __init__
    super(Request, self).__init__(cfg, unreader)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 54, in __init__
    unused = self.parse(self.unreader)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 193, in parse
    self.get_data(unreader, buf, stop=True)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/message.py", line 184, in get_data
    data = unreader.read()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/unreader.py", line 38, in read
    d = self.chunk()
  File "/usr/local/lib/python3.6/site-packages/gunicorn/http/unreader.py", line 65, in chunk
    return self.sock.recv(self.mxchunk)
  File "/usr/local/lib/python3.6/ssl.py", line 994, in recv
    return self.read(buflen)
  File "/usr/local/lib/python3.6/ssl.py", line 871, in read
    return self._sslobj.read(len, buffer)
  File "/usr/local/lib/python3.6/ssl.py", line 633, in read
    v = self._sslobj.read(len)
OSError: [Errno 0] Error

Starting the app with

gunicorn --certfile Config/cert.crt --keyfile Config/cert.key -w 2 -b :8084 --access-logfile - gunicorn_app:app
like image 307
oddball Avatar asked Jul 31 '18 18:07

oddball


1 Answers

Finally, I found it was caused by pod liveness probes, because gunicorn server can't support http and https both together currently, and if we use only https for a public domain, and the http probes check request will be failed with this error.

Solution: Change gunicorn server to Nginx or Apache.

like image 122
Max Mei Avatar answered Oct 19 '22 09:10

Max Mei