lepture / python-livereload

livereload server in python
https://livereload.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.02k stars 150 forks source link

tornado.websocket.WebSocketClosedError #251

Open sansal54 opened 3 years ago

sansal54 commented 3 years ago

When I change something in code pages, I get following error :+1:

Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/cafe_app19-P_30WATA/lib/python3.8/site-packages/tornado/websocket.py", line 1104, in wrapper
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError

I run my flask web app with :

sudo pipenv run python3 main.py

and my code for the server start is :

if __name__ == "__main__":
    # for hot reload during development, debug must be True.
    app.debug = True
    # Reload webpages on changes, without hitting refresh in your browser.
    server = Server(app.wsgi_app)
    server.serve(port=5000, host='localhost')
KrustyHack commented 3 years ago

Ay,

Same here with a Django app :

[I 210926 17:22:27 handlers:92] Reload 1 waiters: application/views.py
[W 210926 17:22:27 iostream:983] Write error on <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>: [Errno 9] Bad file descriptor
Task exception was never retrieved
future: <Task finished name='Task-10' coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at /home/krustyhack/anaconda3/envs/xxx/lib/python3.8/site-packages/tornado/websocket.py:1100> exception=WebSocketClosedError()>
Traceback (most recent call last):
  File "/home/krustyhack/anaconda3/envs/xxx/lib/python3.8/site-packages/tornado/websocket.py", line 1102, in wrapper
    await fut
tornado.iostream.StreamClosedError: Stream is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/krustyhack/anaconda3/envs/xxx/lib/python3.8/site-packages/tornado/websocket.py", line 1104, in wrapper
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError

But it works well when I only edit my HTML templates :

python manage.py livereload
[I 210926 17:26:17 server:335] Serving on http://127.0.0.1:8000
[I 210926 17:26:17 handlers:62] Start watching changes
[I 210926 17:26:17 handlers:64] Start detecting changes
[I 210926 17:26:26 handlers:135] Browser Connected: http://127.0.0.1:8000/
[I 210926 17:26:30 handlers:92] Reload 1 waiters: application/templates/application/index.html
[I 210926 17:26:30 handlers:135] Browser Connected: http://127.0.0.1:8000/
[I 210926 17:26:35 handlers:92] Reload 1 waiters: application/templates/application/index.html
[I 210926 17:26:35 handlers:135] Browser Connected: http://127.0.0.1:8000/
Exordio commented 2 years ago

Same in flask.

[W 220629 18:34:21 iostream:983] Write error on <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=2049, proto=6>: [Errno 9] Bad file descriptor
Task exception was never retrieved
future: <Task finished coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at /home/xxx/workspace/xxx/venv/lib64/python3.6/site-packages/tornado/websocket.py:1100> exception=WebSocketClosedError()>
Traceback (most recent call last):
  File "/home/xxx/workspace/xxx/venv/lib64/python3.6/site-packages/tornado/websocket.py", line 1102, in wrapper
    await fut
tornado.iostream.StreamClosedError: Stream is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xxx/workspace/xxx/venv/lib64/python3.6/site-packages/tornado/websocket.py", line 1104, in wrapper
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
Prinzhorn commented 2 years ago

Might be an upstream race condition with on_close being called before on_message, so it's not removed from the waiters

https://github.com/lepture/python-livereload/blob/8f114c45fd303a2544854f370f80f781e1743e26/livereload/handlers.py#L38-L40

https://github.com/tornadoweb/tornado/issues/2958

cuongtv51 commented 4 months ago

any update for this bug, i have same problem here