-
Notifications
You must be signed in to change notification settings - Fork 138
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
[client-websocket] Random crashes, possible root cause from valgrind (IDFGH-13642) #645
Comments
Is it possible to force only one thread? This code works on my esp32s3 my assumption is the multi threading on Linux is the root cause? |
I can reproduce the reported warnings, and looking into it. My initial guess is that they're false positives, but will take a deeper look.
Could you please check if you still seeing the problems after applying the patch from #647 ?
I'm afraid that wouldn't be very easy, as we use FreeRTOS simulator. If you'd like to experiment with that you can use FreeRTOS mock in IDF, but that's not very straight-forward. |
@david-cermak I was able to get a reproduce on this! On Linux if I read a websocket message <= 127 chars I get the segfault. I will paste a diff so you get it also. I don't understand fully yet why it happens |
@david-cermak Try this The follow WILL NOT crash
Now try adding one more character to that long string. It should then segfault. |
Non-crash output
Crash output
|
The issue starts here The value of |
Thanks for sharing the reproducer. it's because of integer promotions (issue only with the linux target). a quick fix would be: diff --git a/components/tcp_transport/transport_ws.c b/components/tcp_transport/transport_ws.c
index 4aaa1845ed9..76d9c502770 100644
--- a/components/tcp_transport/transport_ws.c
+++ b/components/tcp_transport/transport_ws.c
@@ -497,14 +498,15 @@ static int ws_read_header(esp_transport_handle_t t, char *buffer, int len, int t
if (payload_len == 126) {
// headerLen += 2;
if ((rlen = esp_transport_read_internal(ws, data_ptr, header, timeout_ms)) <= 0) {
ESP_LOGE(TAG, "Error read data");
return rlen;
}
- payload_len = data_ptr[0] << 8 | data_ptr[1];
+ payload_len = data_ptr[0] << 8 | (0xFF & data_ptr[1]);
} else if (payload_len == 127) {
// headerLen += 8; |
@david-cermak nice! That fixed it. Should I open a PR for that. So exciting to be able to run CI/dev locally again. |
@Sean-Der of course, feel free to submit a PR; this code is in IDF, though, and it might take some time till this gets reviewed and merged. PS: also looking into other similar issues, the patch I posted was just the first "naive" shot to fix the issue. |
Sorry I don't fully understand what the next steps are. Are you working on a larger fix/patch @david-cermak and I should leave this alone? I am totally ok if it takes a long time to get merged into IDF! I just want to make sure it gets fixed. |
Yes, please feel free to submit a PR. I'm still investigating other similar issues, but this particular bug definitely needs to be patched, and we'd be happy to merge your PR. Even though it might take a little time to get merged into IDF, your contribution is valuable, and it'll help move things forward. |
Answers checklist.
General issue report
I am trying to use esp-websocket-client and seeing crashes on the Linux build. It isn't 100% reproducible yet, but I am seeing these.
I am also able to reproduce these errors with the example linux application.
The text was updated successfully, but these errors were encountered: