espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.49k stars 7k forks source link

esp_http_server: Adding custom HTTP headers in async requests causes crash (IDFGH-12404) #13430

Closed tmiw closed 1 month ago

tmiw commented 1 month ago

Answers checklist.

IDF version.

v5.2.1

Espressif SoC revision.

ESP32-S3 (QFN56) (revision v0.1)

Operating System used.

macOS

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

Custom Board

Power Supply used.

USB

What is the expected behavior?

I expected to be able to set custom HTTP headers inside a request object created by httpd_req_async_handler_begin and send the response to the browser without any crashes.

What is the actual behavior?

Board reboots while inside the task handling the request (not the HTTP server task).

Steps to reproduce.

Add code similar to the following inside registered esp_http_server handler:

ESP_ERROR_CHECK(httpd_resp_set_type(req, "text/html"));
ESP_ERROR_CHECK(httpd_resp_set_hdr(req, "Content-Security-Policy", "script-src 'self' 'unsafe-inline'"));

[...]

httpd_req_t* asyncReq;
esp_err_t err = httpd_req_async_handler_begin(req, &asyncReq);
if (err == ESP_OK)
{
    // queue request on other thread
}

and then inside the function in the async task handling the request:

if (httpd_resp_send_chunk(message->request, chunk, chunksize) != ESP_OK) 
{
    ...
}

Note that moving httpd_resp_set_* to the async task had no effect on this bug.

Debug Logs.

I (7936) HttpServerTask: Sending file : /index.html (25427 bytes)...
I (8016) HttpServerTask: Sending file : /bootstrap.min.css.gz (27324 bytes)...
I (8126) HttpServerTask: Sending file : /localstyle.css (3249 bytes)...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400556d5  PS      : 0x00060c30  A0      : 0x820968b0  A1      : 0x3fcb0d20  
0x400556d5: strlen in ROM

A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3fcb0cf0  
A10     : 0x00000045  A11     : 0x00000036  A12     : 0x3c27b880  A13     : 0x00000045  
A14     : 0x00000000  A15     : 0x00000002  SAR     : 0x00000008  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xffffffff  
0x400556d5: strlen in ROM
0x400556e5: strlen in ROM

Backtrace: 0x400556d2:0x3fcb0d20 0x420968ad:0x3fcb0d30 0x42037dbb:0x3fcb0d80 0x42130e36:0x3fcb0de0 0x4203c67d:0x3fcb0e00 0x4203c68d:0x3fcb0e30 0x4203a5aa:0x3fcb0e50 0x4203a5bf:0x3fcb0e80 0x42025131:0x3fcb0ea0 0x42025185:0x3fcb0ef0 0x420251e1:0x3fcb0f10 0x40384701:0x3fcb0f30
0x400556d2: strlen in ROM
0x420968ad: httpd_resp_send_chunk at /Users/mooneer/esp-idf/components/esp_http_server/src/httpd_txrx.c:338
0x42037dbb: ezdv::network::HttpServerTask::onHttpServeStaticFileMessage_(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) at /Users/mooneer/ezDV/firmware/main/network/HttpServerTask.cpp:240
0x42130e36: void std::__invoke_impl<void, void (ezdv::network::HttpServerTask::*&)(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), ezdv::network::HttpServerTask*&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>(std::__invoke_memfun_deref, void (ezdv::network::HttpServerTask::*&)(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), ezdv::network::HttpServerTask*&, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:74 (discriminator 4)
0x4203c67d: std::__invoke_result<void (ezdv::network::HttpServerTask::*&)(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), ezdv::network::HttpServerTask*&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>::type std::__invoke<void (ezdv::network::HttpServerTask::*&)(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), ezdv::network::HttpServerTask*&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>(void (ezdv::network::HttpServerTask::*&)(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), ezdv::network::HttpServerTask*&, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:96
 (inlined by) void std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>::__call<void, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&, 0u, 1u, 2u>(std::tuple<ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&>&&, std::_Index_tuple<0u, 1u, 2u>) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/functional:506
 (inlined by) void std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>::operator()<ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*, void>(ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/functional:591
0x4203c68d: void std::__invoke_impl<void, std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>(std::__invoke_other, std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>&, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:61
 (inlined by) std::enable_if<is_invocable_r_v<void, std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>, void>::type std::__invoke_r<void, std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>&, ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*>(std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>&, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/invoke.h:111
 (inlined by) std::_Function_handler<void (ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*), std::_Bind<void (ezdv::network::HttpServerTask::*(ezdv::network::HttpServerTask*, std::_Placeholder<1>, std::_Placeholder<2>))(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)> >::_M_invoke(std::_Any_data const&, ezdv::task::DVTask*&&, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*&&) at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:290
0x4203a5aa: std::function<void (ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*)>::operator()(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) const at /Users/mooneer/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/xtensa-esp-elf/include/c++/13.2.0/bits/std_function.h:591
0x4203a5bf: void ezdv::task::DVTask::HandleEvent_<ezdv::network::HttpServerTask::HttpServeStaticFileMessage>(void*, char const*, long, void*) at /Users/mooneer/ezDV/firmware/main/task/DVTask.h:270
0x42025131: ezdv::task::DVTask::singleMessagingLoop_(long long) at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:321 (discriminator 2)
0x42025185: ezdv::task::DVTask::threadEntry_() at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:341
0x420251e1: ezdv::task::DVTask::ThreadEntry_(ezdv::task::DVTask*) at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:372
0x40384701: vPortTaskWrapper at /Users/mooneer/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134

ELF file SHA256: 8db6f7bb98e440d6

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4213c521
0x4213c521: multi_heap_get_info_tlsf at /Users/mooneer/esp-idf/components/heap/multi_heap.c:399

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x1854
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc04
load:0x403cc700,len:0x2f00
SHA-256 comparison failed:
Calculated: a0908628a94e923787f74f3153cd669c8ce5f79190844874fa999bb3dbaa8532
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway...
entry 0x403c9900

More Information.

I tested with the following changes in my local copy of ESP-IDF and that appeared to resolve the problem:

diff --git a/components/esp_http_server/src/httpd_txrx.c b/components/esp_http_server/src/httpd_txrx.c
index a3c24a10f6..25cbd51a4f 100644
--- a/components/esp_http_server/src/httpd_txrx.c
+++ b/components/esp_http_server/src/httpd_txrx.c
@@ -575,6 +575,20 @@ esp_err_t httpd_req_async_handler_begin(httpd_req_t *r, httpd_req_t **out)
     }
     memcpy(async->aux, r->aux, sizeof(struct httpd_req_aux));

+    // Copy response header block
+    struct httpd_data *hd = (struct httpd_data *) r->handle;
+    struct httpd_req_aux* asyncAux = (struct httpd_req_aux*)async->aux;
+    struct httpd_req_aux* stdAux = (struct httpd_req_aux*)r->aux;
+
+    asyncAux->resp_hdrs = calloc(hd->config.max_resp_headers, sizeof(struct resp_hdr));
+    if (asyncAux->resp_hdrs == NULL)
+    {
+        free(asyncAux);
+        free(async);
+        return ESP_ERR_NO_MEM;
+    }
+    memcpy(asyncAux->resp_hdrs, stdAux->resp_hdrs, hd->config.max_resp_headers * sizeof(struct resp_hdr));
+
     // mark socket as "in use"
     struct httpd_req_aux *ra = r->aux;
     ra->sd->for_async_req = true;
@@ -593,6 +607,7 @@ esp_err_t httpd_req_async_handler_complete(httpd_req_t *r)
     struct httpd_req_aux *ra = r->aux;
     ra->sd->for_async_req = false;

+    free(ra->resp_hdrs);
     free(r->aux);
     free(r);
tmiw commented 1 month ago

Created this bug for traceability and since I'm not 100% sure if the change I tried above is the correct one. If it looks reasonable, I can go ahead and create a PR.

chipweinberger commented 1 month ago

Your changes look reasonable to me. You should open a PR!

Btw, I was the one that implemented async requests in ESP-IDF! =) glad people are using them!

tmiw commented 1 month ago

Your changes look reasonable to me. You should open a PR!

Btw, I was the one that implemented async requests in ESP-IDF! =) glad people are using them!

Nice work! I just created #13462 with the above change :)

mahavirj commented 1 month ago

Closing in favour of https://github.com/espressif/esp-idf/pull/13462

hmalpani commented 1 month ago

Hello @tmiw I was trying to create the issue. I have done these changes in async_handler example:

static esp_err_t submit_async_req(httpd_req_t *req, httpd_req_handler_t handler)
 {
+    ESP_ERROR_CHECK(httpd_resp_set_type(req, "text/html"));
+    ESP_ERROR_CHECK(httpd_resp_set_hdr(req, "Content-Security-Policy", "script-src 'self' 'unsafe-inline'"));
     // must create a copy of the request that we own
     httpd_req_t* copy = NULL;
@@ -133,8 +135,8 @@ static esp_err_t long_async_handler(httpd_req_t *req)
     // send a request count
     char s[100];
     snprintf(s, sizeof(s), "<div>req: %u</div>\n", req_count);
-    httpd_resp_sendstr_chunk(req, s);
-
+    // httpd_resp_sendstr_chunk(req, s);
+    httpd_resp_send_chunk(req, s, strlen(s));
     // then every second, send a "tick"
     for (int i = 0; i < 60; i++) {

I am not observing the crash in this case. Can you please let me know if these are the changes that created the issue on your side.

tmiw commented 4 weeks ago

The example seemed to work for me as well once I increased the stack size of the async tasks.

Anyway, you can try the code for my project (https://github.com/tmiw/ezDV/tree/1.0.2/firmware) with the following patch to disable everything but the HTTP-related logic (and reenable async handling of HTTP requests):

diff --git a/firmware/main/Application.cpp b/firmware/main/Application.cpp
index 17b6378..34b103a 100644
--- a/firmware/main/Application.cpp
+++ b/firmware/main/Application.cpp
@@ -219,6 +219,7 @@ void App::onTaskStart_()
 {
     ESP_LOGI(CURRENT_LOG_TAG, "onTaskStart_");

+#if 0
     // Enable peripheral power.
     enablePeripheralPower_();

@@ -372,19 +373,20 @@ void App::onTaskStart_()
             uiTask_ = new ui::UserInterfaceTask();
             assert(uiTask_ != nullptr);
             start(uiTask_, pdMS_TO_TICKS(1000));
-        
+#endif
+
             // Start Wi-Fi
             wirelessTask_ = new network::WirelessTask(freedvTask_, tlv320Device_, audioMixer_, voiceKeyerTask_);
             assert(wirelessTask_ != nullptr);

-            wirelessTask_->setWiFiOverride(wifiOverrideEnabled_);
+            wirelessTask_->setWiFiOverride(true);
             start(wirelessTask_, pdMS_TO_TICKS(5000));

             // Start storage handling
             settingsTask_ = new storage::SettingsTask();
             assert(settingsTask_ != nullptr);
             settingsTask_->start();
-            
+#if 0            
             softwareUpdateTask_ = new storage::SoftwareUpdateTask();
             assert(softwareUpdateTask_ != nullptr);
             softwareUpdateTask_->start();
@@ -411,6 +413,7 @@ void App::onTaskStart_()
             start(rfComplianceTask_, pdMS_TO_TICKS(1000));
         }
     }
+#endif
 }

 void App::onTaskSleep_()
diff --git a/firmware/main/network/HttpServerTask.cpp b/firmware/main/network/HttpServerTask.cpp
index 611b5fa..98051e8 100644
--- a/firmware/main/network/HttpServerTask.cpp
+++ b/firmware/main/network/HttpServerTask.cpp
@@ -319,6 +319,7 @@ esp_err_t HttpServerTask::ServeStaticPage_(httpd_req_t *req)
     ESP_LOGI(CURRENT_LOG_TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
     set_content_type_from_file(req, filename);

+#if 0
     char* scratchBuf = (char*)heap_caps_malloc(SCRATCH_BUFSIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_32BIT);
     assert(scratchBuf != nullptr);

@@ -344,8 +345,8 @@ esp_err_t HttpServerTask::ServeStaticPage_(httpd_req_t *req)

     ESP_LOGI(CURRENT_LOG_TAG, "Sending %s complete", filename);
     return ESP_OK;
+#endif

-#if 0
     // Async requests are disabled due to ESP-IDF bug with additional HTTP headers.
     // See https://github.com/espressif/esp-idf/issues/13430.
     httpd_req_t* asyncReq;
@@ -359,7 +360,6 @@ esp_err_t HttpServerTask::ServeStaticPage_(httpd_req_t *req)
     }

     return err;
-#endif // 0
 }

 esp_err_t HttpServerTask::ServeWebsocketPage_(httpd_req_t *req)
diff --git a/firmware/partitions.csv b/firmware/partitions.csv
index 6021b49..d1d884a 100644
--- a/firmware/partitions.csv
+++ b/firmware/partitions.csv
@@ -4,12 +4,12 @@ nvs,      data, nvs,     ,        0x6000,
 otadata,  data, ota,     ,        0x2000,
 phy_init, data, phy,     ,        0x1000,
 ota_0,    app,  ota_0,   ,        4000K,
-ota_1,    app,  ota_1,   ,        4000K,
+#ota_1,    app,  ota_1,   ,        4000K,

 # Static HTTP files for web config (1MB)
 # Two slots to correspond with ota_* above.
 http_0,   data, spiffs,  ,        1000K,
-http_1,   data, spiffs,  ,        1000K,
+#http_1,   data, spiffs,  ,        1000K,

 # R/W partition to store voice keyer .wav file (1MB, TBD)
-vk,       data, fat,     ,        1000K,
+#vk,       data, fat,     ,        1000K,

Once it's built and flashed, connect to an access point called "ezDV xxxx" (where the xxxx is the last few octets of the ESP32-S3's MAC address) and attempt to open http://192.168.4.1/ in your browser. In my testing on a nanoESP32-S3 dev board, I'm able to duplicate the crash with the above patch:

I (11639) WirelessTask: Assigned IP 192.168.4.2 to client
I (11659) DVTask: Task FlexVitaTask started
I (11659) FlexVitaTask: New stack high water mark of 1940
I (13669) wifi:<ba-add>idx:3 (ifx:1, 14:98:77:61:65:0f), tid:0, ssn:0, winSize:64
I (15679) HttpServerTask: Sending file : /index.html (25418 bytes)...
I (15749) HttpServerTask: Sending file : /bootstrap.min.css.gz (27324 bytes)...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400556d5  PS      : 0x00060130  A0      : 0x820623d0  A1      : 0x3fcd6bf0  
0x400556d5: strlen in ROM

A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3fcd6bc0  
A10     : 0x00000045  A11     : 0x00000035  A12     : 0x3c1fd308  A13     : 0x00000045  
A14     : 0x00000000  A15     : 0x00000002  SAR     : 0x00000008  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xffffffff  
0x400556d5: strlen in ROM
0x400556e5: strlen in ROM

Backtrace: 0x400556d2:0x3fcd6bf0 0x420623cd:0x3fcd6c00 0x42020b5f:0x3fcd6c50 0x420f5241:0x3fcd6cb0 0x420f5189:0x3fcd6cd0 0x42016ea9:0x3fcd6cf0 0x42016ef5:0x3fcd6d40 0x42016f71:0x3fcd6d60 0x40384631:0x3fcd6d80
0x400556d2: strlen in ROM
0x420623cd: httpd_resp_send_chunk at /Users/mooneer/esp-idf/components/esp_http_server/src/httpd_txrx.c:338
0x42020b5f: ezdv::network::HttpServerTask::onHttpServeStaticFileMessage_(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) at /Users/mooneer/ezDV/firmware/main/network/HttpServerTask.cpp:244
0x420f5241: ezdv::task::DVTask::MessageFnPtrStorage<ezdv::network::HttpServerTask, ezdv::network::HttpServerTask::HttpServeStaticFileMessage>::call(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) at /Users/mooneer/ezDV/firmware/main/task/DVTask.h:205 (discriminator 4)
0x420f5189: void ezdv::task::DVTask::HandleEvent_<ezdv::network::HttpServerTask::HttpServeStaticFileMessage>(void*, char const*, long, void*) at /Users/mooneer/ezDV/firmware/main/task/DVTask.h:335
0x42016ea9: ezdv::task::DVTask::singleMessagingLoop_(long long) at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:341 (discriminator 2)
0x42016ef5: ezdv::task::DVTask::threadEntry_() at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:361
0x42016f71: ezdv::task::DVTask::ThreadEntry_(ezdv::task::DVTask*) at /Users/mooneer/ezDV/firmware/main/task/DVTask.cpp:392
0x40384631: vPortTaskWrapper at /Users/mooneer/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134

ELF file SHA256: aa3ad28aed5f751f

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x42101486
0x42101486: offset_to_block at /Users/mooneer/esp-idf/components/heap/tlsf/tlsf_block_functions.h:79
 (inlined by) block_next at /Users/mooneer/esp-idf/components/heap/tlsf/tlsf_block_functions.h:92
 (inlined by) tlsf_walk_pool at /Users/mooneer/esp-idf/components/heap/tlsf/tlsf.c:772

Hopefully this helps with your testing efforts!

hmalpani commented 1 week ago

Hello @tmiw I am unable to build the example you shared. Can you create a simple example using ESP-IDF which can help recreate the issue? As of now, I am unable to recreate the issue.

tmiw commented 1 week ago

Hello @tmiw I am unable to build the example you shared. Can you create a simple example using ESP-IDF which can help recreate the issue? As of now, I am unable to recreate the issue.

I suspect the submodules and third party libraries my project normally uses are part of why you were having problems. I went ahead and created a new branch in my project that does the following:

  1. Removes all non-firmware code entirely.
  2. Removes all Git submodules and references to third-party libraries in the CMake files.
  3. Removes all code except for the bare minimum needed to duplicate the issue.
  4. Disables PSRAM and removes unneeded partitions (allowing usage on pretty much every ESP32-S3 dev board).

To run:

$ git clone -b esp-idf-13430 https://github.com/tmiw/ezDV.git esp-httpd-crash-demo
$ cd esp-httpd-crash-demo
$ idf.py build flash monitor

# Connect to the "ezDV xxxx" network, then go to http://192.168.4.1/ in your browser

which results in the following crash for me:

I (16262) HttpServerTask: Sending file : /index.html (25429 bytes)...
I (16632) HttpServerTask: Sending file : /bootstrap.min.css.gz (27324 bytes)...
I (16662) HttpServerTask: Sending file : /localstyle.css (3249 bytes)...
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400556d5  PS      : 0x00060c30  A0      : 0x8202c1d8  A1      : 0x3fcc1230  
0x400556d5: strlen in ROM

A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3fcc1200  
A10     : 0x00000002  A11     : 0x00000034  A12     : 0x3c0ad428  A13     : 0x00000002  
A14     : 0x00000000  A15     : 0x00000002  SAR     : 0x00000008  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xffffffff  
0x400556d5: strlen in ROM
0x400556e5: strlen in ROM

Backtrace: 0x400556d2:0x3fcc1230 0x4202c1d5:0x3fcc1240 0x4200ab4b:0x3fcc1290 0x4208be41:0x3fcc12f0 0x4208be19:0x3fcc1310 0x420097f1:0x3fcc1330 0x42009839:0x3fcc1380 0x420098b5:0x3fcc13a0 0x4037fc85:0x3fcc13c0
0x400556d2: strlen in ROM
0x4202c1d5: httpd_resp_send_chunk at /Users/mooneer/esp-idf/components/esp_http_server/src/httpd_txrx.c:338
0x4200ab4b: ezdv::network::HttpServerTask::onHttpServeStaticFileMessage_(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) at /Users/mooneer/ezDV/main/network/HttpServerTask.cpp:185
0x4208be41: ezdv::task::DVTask::MessageFnPtrStorage<ezdv::network::HttpServerTask, ezdv::network::HttpServerTask::HttpServeStaticFileMessage>::call(ezdv::task::DVTask*, ezdv::network::HttpServerTask::HttpServeStaticFileMessage*) at /Users/mooneer/ezDV/main/task/DVTask.h:208 (discriminator 4)
0x4208be19: void ezdv::task::DVTask::HandleEvent_<ezdv::network::HttpServerTask::HttpServeStaticFileMessage>(void*, char const*, long, void*) at /Users/mooneer/ezDV/main/task/DVTask.h:338
0x420097f1: ezdv::task::DVTask::singleMessagingLoop_(long long) at /Users/mooneer/ezDV/main/task/DVTask.cpp:346 (discriminator 2)
0x42009839: ezdv::task::DVTask::threadEntry_() at /Users/mooneer/ezDV/main/task/DVTask.cpp:366
0x420098b5: ezdv::task::DVTask::ThreadEntry_(ezdv::task::DVTask*) at /Users/mooneer/ezDV/main/task/DVTask.cpp:397
0x4037fc85: vPortTaskWrapper at /Users/mooneer/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134

ELF file SHA256: 08eece86af3ea9fc

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x403759fc
0x403759fc: esp_restart_noos at /Users/mooneer/esp-idf/components/esp_system/port/soc/esp32s3/system_internal.c:159