miguelgrinberg / simple-websocket

Simple WebSocket server and client for Python.
MIT License
78 stars 17 forks source link

Race condition present somewhere in receive() #18

Closed bxdn closed 2 years ago

bxdn commented 2 years ago

When testing flask-sock, I ran into an issue where I wasn't getting a ConnectionClosed exception when the client closes the connection (using None timeout). In fact, as it appears that as self.connected is not being toggled, the resulting behavior is that the loop is entered for one more iteration, and my server hangs indefinitely attempting to receive.

I traced it here. Adding a sleep before the event clear makes it work properly, but is obviously a hack.

Edit: It appears that just using a timeout solves the problem. However, you might still want to look at this so I'll keep everything up.

miguelgrinberg commented 2 years ago

@bxdn I'm unable to reproduce this race condition here, but I think I have found the problem anyway. Can I ask you to install the main branch of this package and retest? Thanks!

bxdn commented 2 years ago

That worked beautifully on my end, thanks!