cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.44k stars 56 forks source link

Error when calling `ws.close()` in WebSocket message handler #41

Closed sean324 closed 1 year ago

sean324 commented 1 year ago

Describe the bug Closing a WebSocket in the message handler causes a segmentation fault and the program terminates.

To Reproduce

  1. Enter the following program:
    
    from socketify import App

def ws_message(ws, message, opcode): try: if message == 'Close me.': ws.close() except: print('error')

app = App() app.ws('/ws', { 'message': ws_message }) app.listen(3000, lambda config: print('Listening on port %d' % config.port)) app.run()

3. Start the program.
4. Connect to the server with a WebSocket client.
5. Send "Hello." to server.
6. Notice no error.
7. Send "Close me." to the server.
8. See error and program terminates.

Listening on port 3000 Segmentation fault: 11



**Expected behavior**
For the one connection to close without error and the server keep running to handle and listen for other connections.

**Desktop (please complete the following information):**
 - OS: macOS
 - Version: 12.6.1
 - Architecture: Apple Silicon
cirospaciari commented 1 year ago

Thanks for reporting! I will fix this ASAP 🦾🚀

cirospaciari commented 1 year ago

@seanr3 fixed on last commit, thank's again for the report, please open more issues if you found anything :heart: :mechanical_arm: