Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap tracing 'Standalone' couse HTTPS client crash (IDFGH-3852) #5758

Closed
lbaltoro opened this issue Aug 19, 2020 · 2 comments
Closed

Heap tracing 'Standalone' couse HTTPS client crash (IDFGH-3852) #5758

lbaltoro opened this issue Aug 19, 2020 · 2 comments

Comments

@lbaltoro
Copy link

Environment

  • Development Kit: [ESP32-Ethernet-Kit]
  • Kit version (for WroverKit/PicoKit/DevKitC): [v1.2]
  • Module or chip used: [ESP32-WROVER-B]
  • IDF version (run git describe --tags to find it):
    // v4.2-dev-2077-g7dfe4b468
  • Build System: [idf.py]
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    // (crosstool-NG esp-2020r2) 8.2.0
  • Operating System: [Windows]
  • (Windows only) environment type: [Plain Command Prompt].
  • Using an IDE?: [No]
  • Power Supply: [external 5V]

Problem Description

I'm working on bigger project with ethernet works with MQTT, HTTPS.
Module has often crash with:
'Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.'
when try to connect i.e. google.com by HTTPS.
I tried other HTTPS clients based on pure mbedtls library and module has still error.

I've isolated the problem to the simplest example.
I had combined:
esp-idf\examples\ethernet\basic\ with esp_http_client example
and run, and it works.
But when I set Heap tracing to 'Standalone' it couse crashing.

Expected Behavior

HTTPS Client works with enabled Heap tracing

Actual Behavior

ESP crashes after few HTTPS requests when 'Heap tracing' option is set to Standalone

Steps to reproduce

  1. Add to esp-idf\examples\ethernet\basic https request example
  2. Enable Heap tracing to Standalone

Code to reproduce this issue

// the code should be wrapped in the ```cpp tag so that it will be displayed better.


void app_main(void) {
.....

   xTaskCreate(&https_get_task, "https_get_task", 8192, NULL, 5, NULL);
}




static void https_get_task(void *pvParameters) {
	esp_http_client_config_t config = {
        .host = "google.com",
        .path = "/",
        .transport_type = HTTP_TRANSPORT_OVER_SSL,
    };
	while(1) {
		esp_http_client_handle_t client = esp_http_client_init(&config);
		esp_err_t err = esp_http_client_perform(client);

		if (err == ESP_OK) {
			
			ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %d",
					esp_http_client_get_status_code(client),
					esp_http_client_get_content_length(client));
		} else {
			ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
		}
		
		esp_http_client_cleanup(client);
		vTaskDelay(1000 / portTICK_PERIOD_MS);
	}
	vTaskDelete(NULL);
}

Debug Logs

I (5467) eth_example: ~~~~~~~~~~~
I (5467) eth_example: ETHIP:192.168.0.248
I (5477) eth_example: ETHMASK:255.255.255.0
I (5477) eth_example: ETHGW:192.168.0.101
I (5487) eth_example: ~~~~~~~~~~~
I (12997) eth_example: HTTPS Status = 200, content_length = -1
I (17277) eth_example: HTTPS Status = 200, content_length = -1
Guru Meditation Error: Core  0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400f949c: 22891289 0000f01d 81004136
0x400f949c: mbedtls_mpi_free at C:/Users/Sdarm/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:142

Core  0 register dump:
PC      : 0x400f94a0  PS      : 0x00060930  A0      : 0x00040020  A1      : 0x3ffbf350
0x400f94a0: mbedtls_mpi_free at C:/Users/Sdarm/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:144

A2      : 0x3ffbf370  A3      : 0x3ffc8ce8  A4      : 0x3ffc80e8  A5      : 0x00000000
A6      : 0x3ffc810c  A7      : 0x00060520  A8      : 0x00000000  A9      : 0x3ffbf330
A10     : 0x3ffc80c8  A11     : 0x00000008  A12     : 0xa7caa262  A13     : 0x3ffc8cec
A14     : 0x00000001  A15     : 0x00000000  SAR     : 0x0000001f  EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000

Backtrace:0x400f949d:0x3ffbf350 0x0004001d:0x3ffbf370 |<-CORRUPTED
0x400f949d: mbedtls_mpi_free at C:/Users/Sdarm/esp/esp-idf/components/mbedtls/mbedtls/library/bignum.c:142



ELF file SHA256: 6ddf7841d14b34c5

Rebooting...

Other items if possible

coredump.log
sdkconfig.txt
ethernet_example_main.txt

@github-actions github-actions bot changed the title Heap tracing 'Standalone' couse HTTPS client crash Heap tracing 'Standalone' couse HTTPS client crash (IDFGH-3852) Aug 19, 2020
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting and letting us know, we will look into.

@0xjakob
Copy link
Contributor

0xjakob commented Sep 3, 2020

@lbaltoro We have found the issue, a bug we've been hunting for a few weeks already. Your post helped us fixing it! We'll first apply the fix on master. Then backport it to v4.2.

espressif-bot pushed a commit that referenced this issue Oct 18, 2020
Commit 891eb3b was fixing an issue with PS and EPC1 not being
preserved after the window spill procedure. It did so by saving PS in
a2 and EPC1 in a4. However the a4 register may be a live register of
another window in the call stack, and if it is overwritten and then
spilled to the stack, then the corresponding register value will end
up being corrupted. In practice the problem would show up as an
IllegalInstruction exception, when trying to return from a function
when a0 value was 0x40020.
Fix by using a0 register instead of a4 as scratch. Also fix a comment
about xthal_save_extra_nw, as this function in fact doesn't clobber
a4 or a5 because XCHAL_NCP_NUM_ATMPS is defined as 1.

Closes #5758
espressif-bot pushed a commit that referenced this issue Nov 15, 2020
Commit 891eb3b was fixing an issue with PS and EPC1 not being
preserved after the window spill procedure. It did so by saving PS in
a2 and EPC1 in a4. However the a4 register may be a live register of
another window in the call stack, and if it is overwritten and then
spilled to the stack, then the corresponding register value will end
up being corrupted. In practice the problem would show up as an
IllegalInstruction exception, when trying to return from a function
when a0 value was 0x40020.
Fix by using a0 register instead of a4 as scratch. Also fix a comment
about xthal_save_extra_nw, as this function in fact doesn't clobber
a4 or a5 because XCHAL_NCP_NUM_ATMPS is defined as 1.

Closes #5758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants