I get close reason: ‘Invalid UTF-8 code encountered.’ (code=1007) with
QWebSocket in the following scenario:
- I connect to
- Successfully receive messages for some time period (a few hours).
Binancedisconnects me when its servers load increases (because I have low-priority API) and I get close reason code=1000 that indicates a normal closure.
- Try to reconnect multiple times by calling
Binancecloses the connection with close reason ‘Invalid UTF-8 code encountered.’ (code=1007) that indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message).
- Restart the application manually and connect successfully.
The difficulty of reproducing the bug is that
Binance disconnects me rarely (once a day, for example) and experimentation with disconnecting the network cable from my machine does not have this effect, after I connect the cable back,
QWebSocker reconnects successfully. When I disconnect the network cable I get Error: ‘Unknown error’ (code=-1), Close reason: ” (code=1000).
So, one of the possible assumptions is that something goes wrong with
Binance disconnects it with code 1000.
I tried to recreate
QWebSocket object before reconnecting as a workaround and probably it helped:
Log messages with debug level:
My environment: Windows 10, MSVC 2019, QT 5.15.2
Noticed it disconnected with code 1008: