Monday, December 16, 2013

gevent + pymongo doesn't process replica set host names defined in /etc/hosts

I have a Flask application connecting to a MongoDB replica set via hostname "node1"~"node3"

I can run it properly in dev environment by
python webservice.py
But in production environment, it fails to connect to MongoDB by such a command :
gunicorn  -k gevnet webservice:app -b 0.0.0.0:8100
There's no such issue if I change the work class to sync or eventlet

In the gevent 0.13.x period, I met similar issues caused by gevent DNS mechanism. At that tough time, genent does not process /etc/hosts and /etc/resolv.conf at all. That's you can not reach 10.1.1.47 by hostname "node1" which defined in your /etc/hosts file. :( 

About this gevent + pymongo issue, here's the report, and several workarounds mentioned in the description


After read the 1.0 release note carefully, it may be a pitfall instead of bug. The ares resolver is not only a simple better choice, you must use the "better choice" in some cases.


Fix
for supervisord, add configuration:
environment=GEVENT_RESOLVER=ares
for command line:
env GEVENT_RESOLVER=ares yourcmd...




No comments:

Post a Comment