Closed bryanniwa closed 3 years ago
Thank you so much for providing all the details of your investigation. This saves me a ton of time. :)
Yes, this is an oversight on my part, a socket that returns no data on the recv
function should be assumed to have been closed/abandoned on the other side.
Environment
Flask server using Flask-Socketio and simple-websocket. Client connects using Chromium. Issue is not present with Chrome. Chromium client may be on the same machine as the server or another machine. Tested using Ubuntu 18 on ARM 32bit and WSL2 on Windows 10 64 bit. Tested using python 3.6, 3.8 and 3.9
Steps to reproduce
I have managed to reproduce the issue using the following minimal server.
pkill chromium
or using task manager on windowsMore information
I used the program py-spy to profile the running server and traced the high CPU usage to the
_thread
function in ws.py. As soon as the client is closed,in_data = self.sock.recv(self.receive_bytes)
on line 111 receives empty byte objects as fast as the while loop can process themI managed to fix the problem by adding the following check after the
try-except
block however I'm not sure if it's the best solution.Thanks for all your work