Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
6.x
-
None
Description
With QTcpServer, and other servers, the sockets that they return on new established connection all have their lifetime tied to the server.
QWebSocketServer, however, does not act this way and, upon destruction, leaves the QWebSockets alive but useless since the internal QTcpServer will destroy the QTcpSockets internal to the QWebSockets!
The websocket code works around crashes by checking the QTcpSocket::destroyed signal and then unsetting the socket and making sure, everywhere, that the socket is not null.
This inconsistency makes it harder to get things right without checking documentation when writing code that deals with both behaviors.
So, the ideal way to fix this would be to simply:
1. Set the server as parent of the QWebSockets returned from https://doc.qt.io/qt-6/qwebsocketserver.html#nextPendingConnection
2. Update documentation
However, there may now be code in the wild that are relying on https://doc.qt.io/qt-6/qwebsocket.html#isValid to tell them if the internal TcpSocket is deallocated.