Skip to content

Commit

Permalink
fix(websocket): Prevent crash on network disconnect during send
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xutao authored and david-cermak committed Oct 31, 2024
1 parent a353702 commit 14d50d1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,9 @@ static void esp_websocket_client_task(void *pv)
} else {
esp_websocket_client_error(client, "esp_transport_poll_read() returned %d, errno=%d", read_select, errno);
}
xSemaphoreTakeRecursive(client->lock, lock_timeout);
esp_websocket_client_abort_connection(client, WEBSOCKET_ERROR_TYPE_TCP_TRANSPORT);
xSemaphoreGiveRecursive(client->lock);
}
} else if (WEBSOCKET_STATE_WAIT_TIMEOUT == client->state) {
// waiting for reconnecting...
Expand Down

0 comments on commit 14d50d1

Please sign in to comment.