Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random disconnects, fails on binary ping including 0x00 #151

Open
git-eri opened this issue Feb 4, 2024 · 1 comment
Open

Random disconnects, fails on binary ping including 0x00 #151

git-eri opened this issue Feb 4, 2024 · 1 comment
Assignees

Comments

@git-eri
Copy link

git-eri commented Feb 4, 2024

I experienced random disconnects from my ESP8266 Websocket Client.

The websocket server is uvicorn 0.15.0 and i compared the debug logs from uvicorn with the crashes from the ESP.
Then i saw a pattern: Everytime a binary ping from uvicorn that is including 0x00 the ESP responds with a wrong, cut-off pong.

I took three samples:

Error 1:
uvicorn.error - DEBUG - % sending keepalive ping
uvicorn.error - DEBUG - > PING 71 00 01 c6 [binary, 4 bytes]
uvicorn.error - DEBUG - < PONG 'q' [text, 1 byte]
uvicorn.error - DEBUG - ! timed out waiting for keepalive pong

Error 2:
uvicorn.error - DEBUG - % sending keepalive ping
uvicorn.error - DEBUG - > PING 06 00 5c 93 [binary, 4 bytes]
uvicorn.error - DEBUG - < PONG '\x06' [text, 1 byte]
uvicorn.error - DEBUG - ! timed out waiting for keepalive pong

Error 3:
uvicorn.error - DEBUG - % sending keepalive ping
uvicorn.error - DEBUG - > PING a4 5e b3 00 [binary, 4 bytes]
uvicorn.error - DEBUG - < PONG a4 5e b3 [binary, 3 bytes]
uvicorn.error - DEBUG - ! timed out waiting for keepalive pong

The library seems to cut off before 0x00 and then sends it. 0x71 = "q" as text. I don't know why the first one is interpreted as text and the other as binary but the other ones are obvious.

I know this library isn't that active but this may save someone else from the headache that i had from figuring this out as some time passed on waiting for uvicorn to send the right ping packet and narrowing this down.

Or maybe someone could help with fixing this bug or else i have to search for an alternative.

@abukkawon
Copy link

Hi, I faced the same problem and finally found a solution. 0x00 bytes were lost in functions

WSString fromInterfaceString
WSInterfaceString fromInternalString

The solution is to modify the argument passed to pong in file websockets_endpoint.cpp. It should be pong(std::move(msg.rawData())), when was this pong(internals::fromInterfaceString(msg.data()));
then the data passed through the c_str() function twice, which caused String to be read only until 0x00 was encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants