mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
Merge branch 'fix/fix_possible_ws_server_deadlock_v5.5' into 'release/v5.5'
fix: fix potential ws server deadlock with blocking work queue (v5.5) See merge request espressif/esp-idf!45365
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -576,6 +576,16 @@ esp_err_t httpd_ws_get_frame_type(httpd_req_t *req);
|
||||
*/
|
||||
esp_err_t httpd_sess_trigger_close_(httpd_handle_t handle, struct sock_db *session);
|
||||
|
||||
/**
|
||||
* @brief Directly closes the least recently used session
|
||||
*
|
||||
* @param[in] hd Server instance data
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : if session closed successfully
|
||||
*/
|
||||
esp_err_t httpd_sess_close_lru_direct(struct httpd_data *hd);
|
||||
|
||||
/** End of WebSocket related functions
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -54,7 +54,12 @@ static esp_err_t httpd_accept_conn(struct httpd_data *hd, int listen_fd)
|
||||
if (hd->config.lru_purge_enable == true) {
|
||||
if (!httpd_is_sess_available(hd)) {
|
||||
/* Queue asynchronous closure of the least recently used session */
|
||||
#if CONFIG_HTTPD_QUEUE_WORK_BLOCKING
|
||||
/* In case of blocking mode, close the least recently used session directly */
|
||||
return httpd_sess_close_lru_direct(hd);
|
||||
#else
|
||||
return httpd_sess_close_lru(hd);
|
||||
#endif /* CONFIG_HTTPD_QUEUE_WORK_BLOCKING */
|
||||
/* Returning from this allows the main server thread to process
|
||||
* the queued asynchronous control message for closing LRU session.
|
||||
* Since connection request hasn't been addressed yet using accept()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -498,3 +498,21 @@ void httpd_sess_close_all(struct httpd_data *hd)
|
||||
};
|
||||
httpd_sess_enum(hd, enum_function, &context);
|
||||
}
|
||||
|
||||
esp_err_t httpd_sess_close_lru_direct(struct httpd_data *hd)
|
||||
{
|
||||
enum_context_t context = {
|
||||
.task = HTTPD_TASK_FIND_LOWEST_LRU,
|
||||
.lru_counter = UINT64_MAX,
|
||||
.fd = -1
|
||||
};
|
||||
httpd_sess_enum(hd, enum_function, &context);
|
||||
if (!context.session) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, LOG_FMT("Directly closing session with fd %d"), context.session->fd);
|
||||
// Call httpd_sess_delete directly instead of going through work queue
|
||||
httpd_sess_delete(hd, context.session);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user