Closed aaugustin closed 1 month ago
Once this is fixed, many cases in section 6 in the Autobahn test suite should result in code 1002 rather than 1000.
Aligning the behavior of the threading implementation to the asyncio implementation (which I wanted to do anyway) will make it easier to get this right for both implementations.
All implementations store incoming messages to a queue; then the application reads from this queue.
In the legacy asyncio, UTF-8 decoding happens in
WebSocketCommonProtocol.read_message
, before storing messages in the queue. As a consequence, if websockets receives a message containing invalid UTF-8 — which is vanishingly uncommon these days — aUnicodeDecodeError
is raised and websockets immediately closes the connection with code 1002.The new asyncio implementation stores messages as-is; UTF-8 decoding happens in
Assembler.get
. In case of invalid UTF-8, anUnicodeDecodeError
is raised when the application callsrecv
; websockets keeps the connection open and continues happily, when it should close it.The new implementation has two benefits and one downside:
Also, while
Frame.parse
is documented to raiseUnicodeDecodeError
, it doesn't look like this can happen. Error handling inProtocol.parse
is for the case whenrecv_frame
raisesUnicodeDecodeError
.