forked from espressif/esp-protocols
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: https://github.com/espressif/esp-protocols/pull/629
This commit is contained in:
@ -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...
|
||||
|
Reference in New Issue
Block a user