{"action":"created","issue":{"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/631","repository_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO","labels_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/631/labels{/name}","comments_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/631/comments","events_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/631/events","html_url":"https://github.com/miguelgrinberg/Flask-SocketIO/issues/631","id":294188483,"number":631,"title":"IOError: unable to complete websocket handshake while running in  uwsgi+Nginx","user":{"login":"Rakin061","id":27331118,"avatar_url":"https://avatars0.githubusercontent.com/u/27331118?v=4","gravatar_id":"","url":"https://api.github.com/users/Rakin061","html_url":"https://github.com/Rakin061","followers_url":"https://api.github.com/users/Rakin061/followers","following_url":"https://api.github.com/users/Rakin061/following{/other_user}","gists_url":"https://api.github.com/users/Rakin061/gists{/gist_id}","starred_url":"https://api.github.com/users/Rakin061/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rakin061/subscriptions","organizations_url":"https://api.github.com/users/Rakin061/orgs","repos_url":"https://api.github.com/users/Rakin061/repos","events_url":"https://api.github.com/users/Rakin061/events{/privacy}","received_events_url":"https://api.github.com/users/Rakin061/received_events","type":"User","site_admin":false},"labels":[{"id":79522651,"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":33,"created_at":"2018-02-04T10:59:02Z","updated_at":"2018-02-20T22:52:31Z","closed_at":null,"author_association":"NONE","body":"I have been planning to deploy a flask-SocketIO application into production using **uwsgi** server behind **Nginx** \r\n\r\nVersions including relevant dependencies of my virtual environment:-\r\n\r\n```\r\nOS:-  Ubuntu 16.04.3 LTS\r\nuWsgi:-   2.0.15 \r\nnginx:-   1.12.2\r\npython:- 2.7.12\r\nFalsk:-   0.12.2\r\nFlask-SocketIO:-  2.9.2\r\ngevent:- 1.2.2\r\n\r\n```\r\n\r\nI am intended to run the uwsgi server through systemd and load the uwsgi configurations from a .ini file. \r\n\r\nHere's my `wsgi.py` file:\r\n```\r\nfrom server import app\r\nif __name__ == \"__main__\":\r\n    app.run()\r\n```\r\n\r\nHere's the configuration file `myproject.ini` for **uwsgi**\r\n\r\n```\r\n[uwsgi]\r\nmodule = wsgi:app\r\n\r\nhttp = :5000\r\ngevent = 1000\r\nhttp-websockets = true\r\n\r\nmaster = true\r\nprocesses = 5\r\n\r\nsocket = myproject.sock\r\nchmod-socket = 660\r\nvacuum = true\r\n\r\ndie-on-term = true\r\n```\r\n\r\n\r\nHere's the `myproject.service` file in `/etc/systemd/system`\r\n\r\n```\r\n[Unit]\r\nDescription=uWSGI instance to serve myproject\r\nAfter=network.target\r\n\r\n[Service]\r\nUser=user\r\nGroup=www-data\r\nWorkingDirectory=/home/user/myproject\r\nEnvironment=\"PATH=/home/user/myproject/virtual_frame/bin\"\r\nExecStart=/home/user/myproject/virtual_frame/bin/uwsgi --ini myproject.ini\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n```\r\n\r\n\r\nAnd, finally my nginx configuration file:\r\n\r\n```\r\n server {\r\n    listen 80;\r\n    server_name 10.11.201.82:5000;\r\n\r\n    location / {\r\n        include uwsgi_params;\r\n        uwsgi_pass unix:/home/user/myproject/myproject.sock;\r\n        uwsgi_ignore_client_abort on;\r\n    }\r\n\r\n    location /socket.io {\r\n        include proxy_params;\r\n        proxy_http_version 1.1;\r\n        proxy_buffering off;\r\n        proxy_set_header Upgrade $http_upgrade;\r\n        proxy_set_header Connection \"Upgrade\";\r\n        proxy_pass http://10.11.201.82:5000/socket.io;\r\n    }\r\n\r\n}\r\n```\r\n\r\nErrors:-\r\n\r\nActually I'm getting different errors from several times. \r\n\r\n##  **1) IOError: unable to complete websocket handshake**\r\n\r\nHere's my project status while running:_\r\n```\r\nuser@user-HVM-domU:~/myproject$ sudo journalctl -u myproject -n 20\r\n-- Logs begin at à¦¶à¦¨à¦¿ 2018-02-03 09:52:05 +06, end at à¦°à¦¬à¦¿ 2018-02-04 15:27:48 +06. --\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/flask/app.py\", line 1997, i\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     return self.wsgi_app(environ, start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/flask_socketio/__init__.py\"\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/engineio/middleware.py\", li\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     return self.engineio_app.handle_request(environ, start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/socketio/server.py\", line 3\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     return self.eio.handle_request(environ, start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/engineio/server.py\", line 2\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     environ, start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/engineio/socket.py\", line 8\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/engineio/socket.py\", line 1\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     return ws(environ, start_response)\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:   File \"/home/user/myproject/virtual_frame/local/lib/python2.7/site-packages/engineio/async_gevent_uwsgi\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]:     uwsgi.websocket_handshake()\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]: IOError: unable to complete websocket handshake\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]: [pid: 23604|app: 0|req: 21/79] 10.11.201.82 () {50 vars in 1028 bytes} [Sun Feb  4 15:27:39 2018] GET /s\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]: [pid: 23604|app: 0|req: 22/80] 10.11.201.82 () {38 vars in 784 bytes} [Sun Feb  4 15:27:39 2018] GET /so\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:27:39 user-HVM-domU uwsgi[23592]: [pid: 23604|app: 0|req: 23/81] 10.11.201.82 () {42 vars in 845 bytes} [Sun Feb  4 15:27:39 2018]\r\n```\r\n\r\n## **2) IOError: write error: uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.**\r\n\r\n```\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:16:53 user-HVM-domU uwsgi[23421]: [pid: 23433|app: 0|req: 52/94] 10.11.201.82 () {42 vars in 845 bytes} [Sun Feb  4 15:16:38 2018] POST /s\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:16:53 user-HVM-domU uwsgi[23421]: [pid: 23433|app: 0|req: 52/95] 10.11.201.82 () {38 vars in 783 bytes} [Sun Feb  4 15:16:30 2018] GET /so\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:16:55 user-HVM-domU uwsgi[23421]: [pid: 23433|app: 0|req: 54/96] 10.11.201.82 () {42 vars in 843 bytes} [Sun Feb  4 15:16:55 2018] POST /s\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:16:55 user-HVM-domU uwsgi[23421]: [pid: 23433|app: 0|req: 54/97] 10.11.201.82 () {38 vars in 783 bytes} [Sun Feb  4 15:16:53 2018] GET /so\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:17:08 user-HVM-domU uwsgi[23421]: Sun Feb  4 15:17:08 2018 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line \r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:17:08 user-HVM-domU uwsgi[23421]: IOError: write error\r\nà¦«à§‡à¦¬à§à¦°à§ 04 15:17:08 user-HVM-domU uwsgi[23421]: [pid: 23433|app: 0|req: 55/98] 10.11.201.82 () {44 vars in 867 bytes} [Sun Feb  4 15:16:08 2018] GET /so\r\n\r\n```\r\n\r\n## **3) Nginx error log**\r\n\r\nLast 20 line of  /var/log/nginx/error.log\r\n\r\n```\r\n2018/02/04 15:24:42 [error] 23563#23563: *109 upstream prematurely closed connection while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=websocket&sid=b95aa3f7a7374706a7d09d857c1e69fe HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=websocket&sid=b95aa3f7a7374706a7d09d857c1e69fe\", host: \"10.11.201.82\"\r\n2018/02/04 15:25:40 [error] 23560#23560: *83 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=polling&t=1517736280486-2&sid=998d555f29cc49f3949bf080b5c2820c HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736280486-2&sid=998d555f29cc49f3949bf080b5c2820c\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\"\r\n2018/02/04 15:25:49 [error] 23563#23563: *98 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=polling&t=1517736289238-36&sid=6535da975fee43bdb49be5f061e04522 HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736289238-36&sid=6535da975fee43bdb49be5f061e04522\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\"\r\n2018/02/04 15:25:50 [error] 23563#23563: *138 upstream prematurely closed connection while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=polling&t=1517736290606-40&sid=c13d0711b34b49cb8d5d973642369c33 HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736290606-40&sid=c13d0711b34b49cb8d5d973642369c33\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\"\r\n2018/02/04 15:25:54 [error] 23563#23563: *143 upstream prematurely closed connection while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=polling&t=1517736294273-52&sid=aec315362ea644fe93035f7d8c5519a6 HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736294273-52&sid=aec315362ea644fe93035f7d8c5519a6\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\"\r\n2018/02/04 15:25:56 [error] 23560#23560: *83 upstream prematurely closed connection while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"GET /socket.io/?EIO=3&transport=polling&t=1517736346555-72&sid=933777c0ced64dc4a459b1ebe33a0d21 HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736346555-72&sid=933777c0ced64dc4a459b1ebe33a0d21\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\"\r\n2018/02/04 15:25:56 [error] 23560#23560: *83 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.11.201.82, server: 10.11.201.82, request: \"POST /socket.io/?EIO=3&transport=polling&t=1517736356497-73&sid=933777c0ced64dc4a459b1ebe33a0d21 HTTP/1.1\", upstream: \"http://10.11.201.82:5000/socket.io/?EIO=3&transport=polling&t=1517736356497-73&sid=933777c0ced64dc4a459b1ebe33a0d21\", host: \"10.11.201.82\", referrer: \"http://10.11.201.82/\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/comments/367149406","html_url":"https://github.com/miguelgrinberg/Flask-SocketIO/issues/631#issuecomment-367149406","issue_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/631","id":367149406,"user":{"login":"Rakin061","id":27331118,"avatar_url":"https://avatars0.githubusercontent.com/u/27331118?v=4","gravatar_id":"","url":"https://api.github.com/users/Rakin061","html_url":"https://github.com/Rakin061","followers_url":"https://api.github.com/users/Rakin061/followers","following_url":"https://api.github.com/users/Rakin061/following{/other_user}","gists_url":"https://api.github.com/users/Rakin061/gists{/gist_id}","starred_url":"https://api.github.com/users/Rakin061/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rakin061/subscriptions","organizations_url":"https://api.github.com/users/Rakin061/orgs","repos_url":"https://api.github.com/users/Rakin061/repos","events_url":"https://api.github.com/users/Rakin061/events{/privacy}","received_events_url":"https://api.github.com/users/Rakin061/received_events","type":"User","site_admin":false},"created_at":"2018-02-20T22:52:31Z","updated_at":"2018-02-20T22:52:31Z","author_association":"NONE","body":"Ok. But my question is why it's working when passing certificate file as a argument in socketio.run() \r\n\r\nIsn't that surprising and illogical ? ? "}}
{"actor":{"display_login":"Rakin061"}}