miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.31k stars 888 forks source link

Error when using gevent with allow_unsafe_werkzeug #2001

Closed alethiophile closed 11 months ago

alethiophile commented 11 months ago

Describe the bug When using gevent and gevent-websocket, if the allow_unsafe_werkzeug argument is passed to the SocketIO constructor, the server fails to start:

openakun-app-1       | Traceback (most recent call last):
openakun-app-1       |   File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
openakun-app-1       |   File "/venv/lib/python3.10/site-packages/gevent/baseserver.py", line 34, in _handle_and_close_when_done
openakun-app-1       |     return handle(*args_tuple)                                                                                                                                                                                        
openakun-app-1       |   File "/venv/lib/python3.10/site-packages/gevent/server.py", line 209, in wrap_socket_and_handle
openakun-app-1       |     with _closing_socket(self.wrap_socket(client_socket, **self.ssl_args)) as ssl_socket:                                                                                                                             
openakun-app-1       | TypeError: wrap_socket() got an unexpected keyword argument 'allow_unsafe_werkzeug'      
openakun-app-1       | 2023-07-26T17:28:56Z <Greenlet at 0x7f1915236480: _handle_and_close_when_done(<bound method StreamServer.wrap_socket_and_handle , <bound method StreamServer.do_close of <WSGIServer, (<gevent._socket3.socket [closed
] at 0x7f19168a5ea)> failed with TypeError                                                                                                                                                                                                   openakun-app-1       |                    

To Reproduce Steps to reproduce the behavior:

  1. Install gevent and gevent-websocket
  2. Run socketio with the allow_unsafe_werkzeug option
  3. note crash

Expected behavior If the server is going to be using gevent anyway, it should just ignore allow_unsafe_werkzeug, since the werkzeug server never comes into it.

miguelgrinberg commented 11 months ago

Can I ask you to install the main branch and confirm that the bug is addressed with the above commit? Thanks.

alethiophile commented 11 months ago

Yeah, it works fine now.

Thanks.