Skip to content

Commit fbc38a9

Browse files
committed
Merge branch 'fix/async_handler_example_stack_overflow_issue' into 'master'
fix(esp_http_server): Async handler example stack overflow fix See merge request espressif/esp-idf!38586 Related: #15587
2 parents d6fb99b + 160336f commit fbc38a9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

examples/protocols/http_server/async_handlers/main/Kconfig.projbuild

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ menu "Example Configuration"
77
The maximum number of simultaneous async requests that the
88
web server can handle.
99

10+
config EXAMPLE_ASYNC_WORKER_TASK_STACK_SIZE
11+
int "Async Worker Task Stack Size"
12+
default 2560
13+
help
14+
The stack size allocated for each async worker task.
15+
1016
endmenu

examples/protocols/http_server/async_handlers/main/main.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333

3434
#define ASYNC_WORKER_TASK_PRIORITY 5
35-
#define ASYNC_WORKER_TASK_STACK_SIZE 2048
35+
#define ASYNC_WORKER_TASK_STACK_SIZE CONFIG_EXAMPLE_ASYNC_WORKER_TASK_STACK_SIZE
3636

3737
static const char *TAG = "example";
3838

@@ -104,7 +104,11 @@ static esp_err_t long_async(httpd_req_t *req)
104104
// send a request count
105105
char s[100];
106106
snprintf(s, sizeof(s), "<div>req: %u</div>\n", req_count);
107-
httpd_resp_sendstr_chunk(req, s);
107+
esp_err_t err = httpd_resp_sendstr_chunk(req, s);
108+
if (err != ESP_OK) {
109+
ESP_LOGE(TAG, "Failed to send string chunk: %s", esp_err_to_name(err));
110+
return err;
111+
}
108112

109113
// then every second, send a "tick"
110114
for (int i = 0; i < 60; i++) {
@@ -116,11 +120,19 @@ static esp_err_t long_async(httpd_req_t *req)
116120

117121
// send a tick
118122
snprintf(s, sizeof(s), "<div>%u</div>\n", i);
119-
httpd_resp_sendstr_chunk(req, s);
123+
err = httpd_resp_sendstr_chunk(req, s);
124+
if (err != ESP_OK) {
125+
ESP_LOGE(TAG, "Failed to send string chunk: %s", esp_err_to_name(err));
126+
return err;
127+
}
120128
}
121129

122130
// send "complete"
123-
httpd_resp_sendstr_chunk(req, NULL);
131+
err = httpd_resp_sendstr_chunk(req, NULL);
132+
if (err != ESP_OK) {
133+
ESP_LOGE(TAG, "Failed to send string chunk: %s", esp_err_to_name(err));
134+
return err;
135+
}
124136

125137
return ESP_OK;
126138
}

0 commit comments

Comments
 (0)