miguelgrinberg / python-engineio

Python Engine.IO server and client
MIT License
232 stars 147 forks source link

Bug disconnection with uwsgi #330

Closed johaven closed 1 year ago

johaven commented 1 year ago

Versions: Flask-SocketIO 5.3.5 python-engineio 4.6.1 python-socketio 5.8.0 gevent 23.7.0 greenlet 2.0.2 uWSGI 2.0.22

Error during disconnection:

[uwsgi-websocket] "GET /socket.io/?EIO=4&transport=websocket" no PONG received in 3 seconds !!!
[BUG] current_wsgi_req NOT FOUND !!!
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
  File "/var/www/webapp/venv/lib64/python3.9/site-packages/engineio/socket.py", line 223, in writer
    ws.close()
  File "/var/www/webapp/venv/lib64/python3.9/site-packages/engineio/async_drivers/gevent_uwsgi.py", line 70, in close
    uwsgi.disconnect()
SystemError: you can call uwsgi api function only from the main callable
2023-09-06T08:59:59Z <Thread at 0x7febf566dae0: writer> failed with SystemError

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 833, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 859, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 848, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
  File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
  File "/var/www/webapp/venv/lib64/python3.9/site-packages/engineio/socket.py", line 223, in writer
    ws.close()
  File "/var/www/webapp/venv/lib64/python3.9/site-packages/engineio/async_drivers/gevent_uwsgi.py", line 70, in close
    uwsgi.disconnect()
SystemError: you can call uwsgi api function only from the main callable

Seems to be related to:

https://github.com/unbit/uwsgi/pull/985 https://github.com/pinterest/querybook/issues/1319

stianpr commented 1 year ago

We've been having similar issues with this:

Versions: Flask-SocketIO 5.3.1 python-engineio 4.6.1 (and 4.7.0 after latest deploy) python-socketio 5.9.0 gevent 22.10.2 greenlet 2.0.1 uWSGI 2.0.21

Exception:

SystemError: you can call uwsgi api function only from the main callable
  File "src/gevent/greenlet.py", line 833, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 859, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 848, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
  File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
  File "engineio/socket.py", line 223, in writer
    ws.close()
  File "engineio/async_drivers/gevent_uwsgi.py", line 70, in close
    uwsgi.disconnect()
stianpr commented 1 year ago

Any updates on this?

amks1 commented 1 year ago

I have the same issue, python-engineio v4.5.1 is the latest version I'm able to run that doesn't give the above error.

miguelgrinberg commented 1 year ago

Could you test the main branch to confirm the problem is gone? Thanks.

amks1 commented 1 year ago

Could you test the main branch to confirm the problem is gone? Thanks.

Yes, the problem seems to be fixed in the main branch now. 👍

miguelgrinberg commented 1 year ago

4.7.1 is out with this fix.

okayhooni commented 1 year ago

@johaven Thank you for noticing me this issue with mention. :)