Hi,
I’m using python-socketio
with Sanic, and having a client (front-end) running ReactJS (using react-boilerplate.
The Sanic app sometimes crashes when the client performs a hot-reload. Here is the error logs retrieved from journalctl
, the service’s name is Ora socketio
:
Oct 31 16:04:39 ora-backend systemd[1]: Stopping Running Ora socketio...
Oct 31 16:04:39 ora-backend python3.7[15005]: [2019-10-31 16:04:39 +0000] [15005] [INFO] Stopping worker [15005]
Oct 31 16:04:39 ora-backend python3.7[15005]: [2019-10-31 16:04:39 +0000] [15005] [ERROR] Experienced exception while trying to serve
Oct 31 16:04:39 ora-backend python3.7[15005]: Traceback (most recent call last):
Oct 31 16:04:39 ora-backend python3.7[15005]: File "/root/venv/lib/python3.7/site-packages/sanic/app.py", line 1135, in run
Oct 31 16:04:39 ora-backend python3.7[15005]: serve(**server_settings)
Oct 31 16:04:39 ora-backend python3.7[15005]: File "/root/venv/lib/python3.7/site-packages/sanic/server.py", line 825, in serve
Oct 31 16:04:39 ora-backend python3.7[15005]: loop.run_until_complete(asyncio.sleep(0.1))
Oct 31 16:04:39 ora-backend python3.7[15005]: File "uvloop/loop.pyx", line 1415, in uvloop.loop.Loop.run_until_complete
Oct 31 16:04:39 ora-backend python3.7[15005]: RuntimeError: Event loop stopped before Future completed.
Oct 31 16:04:39 ora-backend python3.7[15005]: Traceback (most recent call last):
Oct 31 16:04:39 ora-backend python3.7[15005]: File "app_socketio.py", line 6, in <module>
Oct 31 16:04:39 ora-backend python3.7[15005]: app.run(**SOCKETIO_RUN_CONFIG)
Oct 31 16:04:39 ora-backend python3.7[15005]: File "/root/venv/lib/python3.7/site-packages/sanic/app.py", line 1135, in run
Oct 31 16:04:39 ora-backend python3.7[15005]: serve(**server_settings)
Oct 31 16:04:39 ora-backend python3.7[15005]: File "/root/venv/lib/python3.7/site-packages/sanic/server.py", line 825, in serve
Oct 31 16:04:39 ora-backend python3.7[15005]: loop.run_until_complete(asyncio.sleep(0.1))
Oct 31 16:04:39 ora-backend python3.7[15005]: File "uvloop/loop.pyx", line 1415, in uvloop.loop.Loop.run_until_complete
Oct 31 16:04:39 ora-backend python3.7[15005]: RuntimeError: Event loop stopped before Future completed.
Oct 31 16:04:39 ora-backend systemd[1]: ora_socketio.service: Main process exited, code=exited, status=1/FAILURE
Oct 31 16:04:39 ora-backend systemd[1]: ora_socketio.service: Failed with result 'exit-code'.
Do you know what the causes of this are ?
Here is the code I use for the Sanic app and the client:
Sanic app
Version: 19.6.3
# app_socketio.py
SOCKETIO_RUN_CONFIG = {
"host": "0.0.0.0",
"port": 8080,
"debug": False,
"access_log": False,
"workers": 1,
"protocol": WebSocketProtocol,
}
app.run(**SOCKETIO_RUN_CONFIG)
Client (ReactJS)
const socket = socketIOClient('http://157.230.253.130:8080', {
transportOptions: {
polling: {
extraHeaders: {
Authorization: `Bearer ${access_token}`,
},
},
},
transports: ['polling'],
});