gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

Unable to launch gunicorn + gevent: `OSError: [Errno 92] Protocol not available`

Open xingdongzhe opened this issue 1 year ago • 0 comments

@benoitc I found that gunicorn launch fail with gevent

  • It only launch fail when Python version >= 3.7, this is because of gevent support for Python3.7
  • here code to repduce: gunicorn -c gunicorn_config.py main:app
  • Python==3.8.15
  • gunicorn ==21.2.0
  • gevent==23.9.1
# gunicorn_config.py

# import gevent.monkey

# gevent.monkey.patch_all()
import logging

bind = "127.0.0.1:8888"
workers = 1

backlog = 2048
worker_class = "gevent"
# worker_class = "tornado"
# worker_class = "uvicorn.workers.UvicornWorker"
debug = True
worker_connections = 3

chdir = "."
daemon = False
accesslog = "./access.log"
errorlog = "./error.log"
loglevel = "debug"

# main.py
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"
  • errlog.log output
[2024-02-03 17:02:36 +0800] ERROR /home/linsg/work/tornado_demo/venv/lib/python3.8/site-packages/gunicorn/glogging.py 284 15652 139651797619584 Exception in worker process
Traceback (most recent call last):
  File "/home/linsg/work/tornado_demo/venv/lib/python3.8/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
    worker.init_process()
  File "/home/linsg/work/tornado_demo/venv/lib/python3.8/site-packages/gunicorn/workers/ggevent.py", line 145, in init_process
    self.patch()
  File "/home/linsg/work/tornado_demo/venv/lib/python3.8/site-packages/gunicorn/workers/ggevent.py", line 44, in patch
    sockets.append(socket.socket(s.FAMILY, socket.SOCK_STREAM,
  File "/home/linsg/work/tornado_demo/venv/lib/python3.8/site-packages/gevent/_socket3.py", line 125, in __init__
    self._sock = self._gevent_sock_class(family, type, proto, fileno)
OSError: [Errno 92] Protocol not available
  • gevent suport for Python3.7
  • proto paramater change default value to -1 when fileno is not None. When proto=-1 will get overview output
  • And gunicorn code of socket's configuration will use the default value that is -1 for proto
sockets.append(socket.socket(s.FAMILY, socket.SOCK_STREAM, fileno=s.sock.fileno()))

xingdongzhe avatar Feb 03 '24 15:02 xingdongzhe