I have a Flask app and I use the gunicorn as a web server with eventlet (python -m gunicorn -k eventlet <app_here>). One of the submodules is using the Google Cloud Pub/Sub service and is the one that's causing the worker to restart. In particular, it's the 3rd line here:
subscription_name = 'projects/{project_id}/subscriptions/{sub}'.format(project_id=pro_id, sub=sub_id)
subscriber_ = pubsub_v1.SubscriberClient(credentials=credentials_)
streaming_pull_future = subscriber_.subscribe(subscription=subscription_path, callback=test_callback) # ISSUE LINE
The error I get is:
[CRITICAL] WORKER TIMEOUT
Listening for messages on projects/....
[ERROR] Socket error processing request.
Traceback (most recent call last):
File "../python3.8/site-packages/gunicorn/workers/base_async.py", line 65, in handle
util.reraise(*sys.exc_info())
File "../python3.8/site-packages/gunicorn/util.py", line 626, in reraise
raise value
File "../python3.8/site-packages/gunicorn/workers/base_async.py", line 38, in handle
listener_name = listener.getsockname()
OSError: [Errno 9] Bad file descriptor
What I tried so far
- If I remove
gunicornandeventlet(i.e.python <app_here>) that module works as expected but of course not the rest (backend/frontend). - I've tested with different
gunicornandeventletversions, with no luck. - If I synchronously pull for new messages (and remove the
subscriber_.subscribe()), it works but it's not the recommended way.
The implementation of the pubsub is based on gcp pubsub docs with simply adding some credentials.
python3.8
eventlet 0.30.2
gunicorn 20.1.0
google-api-core 2.11.1
google-cloud-pubsub 2.18
Flask 2.2.3
Is there a setting in the pubsub or the eventlet that I'm missing and would make it work?