Hulii Borys
Hulii Borys

Reputation: 272

flask-socketio + gunicorn + nginx through unix socket file [Errno -2]

I create site on Flask. All communication with server is going through WebSockets. When i use gunicorn with TCP/IP:

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app --bind=127.0.0.1:8800

Everything works fine. But when i use Unix socket file:

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app -b unix:///var/sockets/gunicorn.sock

I have errors in log:

[root@localhost legalize]# gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker chat:app -b unix:///var/sockets/gunicorn.sock
2015-04-03 13:32:26 [25392] [INFO] Starting gunicorn 18.0
2015-04-03 13:32:26 [25392] [INFO] Listening at: unix:/var/sockets/gunicorn.sock (25392)
2015-04-03 13:32:26 [25392] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
2015-04-03 13:32:26 [25397] [INFO] Booting worker with pid: 25397
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)
FAILED to start flash policy server: [Errno -2] Name or service not known: ('/', 10843)

How i can fix this error?

Upvotes: 2

Views: 1954

Answers (1)

Miguel Grinberg
Miguel Grinberg

Reputation: 67479

Project gevent-socketio (the dependency of Flask-SocketIO that handles the Socket.IO protocol) starts a secondary web server used for the Flash transport. This server listens on the same host as your main server, but at port 10843. Clearly that logic fails when the main server listens on a unix socket.

Do you need to offer Flash support? If not, I recommend that you disable it altogether, by setting environment variable POLICY_SERVER to a non-null value. Here is the logic that disables the policy server, in case you are curious: https://github.com/abourget/gevent-socketio/blob/668d11edbd62052cde1583be1e1d0512c930f16d/socketio/sgunicorn.py#L43-L47

Upvotes: 1

Related Questions