Skip to content

Commit a453ca1

Browse files
xutaodavid-cermak
authored andcommitted
fix(websocket): Prevent crash on network disconnect during send
When WiFi disconnects, `esp_websocket_client_task` continues polling `esp_transport_poll_read()` with a default 1-second timeout. If a timeout triggers `esp_websocket_client_abort_connection`, certain resources are released. However, if `esp_websocket_client_send_with_exact_opcode` is still blocked at this point, it will cause a crash when it times out and accesses the released handle. This fix prevents potential crashes by ensuring proper synchronization between abort and send functions. Merges: #629
1 parent 72f4f7c commit a453ca1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,9 @@ static void esp_websocket_client_task(void *pv)
10831083
} else {
10841084
esp_websocket_client_error(client, "esp_transport_poll_read() returned %d, errno=%d", read_select, errno);
10851085
}
1086+
xSemaphoreTakeRecursive(client->lock, lock_timeout);
10861087
esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
1088+
xSemaphoreGiveRecursive(client->lock);
10871089
}
10881090
} else if (WEBSOCKET_STATE_WAIT_TIMEOUT == client->state) {
10891091
// waiting for reconnecting...

0 commit comments

Comments
 (0)