esp-idf: HELP!!!!! Exception / Panic in function localtime_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/time/lcltime_r.c:123 (IDFGH-9401)
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
framework-espidf @ 3.50000.0 (5.0.0)
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
PlatformIO, package Espressif 32 version 6.0.1
Power Supply used.
USB
What is the expected behavior?
After upgrading to esp-idf version 5.0.0, the localtime_r function periodically began to panic with a controller reboot. Not constantly, and randomly - once an hour or every few hours. On version 4.4.3 and below, the same code worked absolutely stably.
What is the actual behavior?
The trace outputs the following:
C:\PlatformIO\security_v4225\ota>c:\Users\kotyara12\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-addr2line.exe -pfiaC -e c:\PlatformIO\security_v4225\ota\firmware\firmware.elf 0x400d4590 0x400ecdae 0x40082829 0x40083512 0x400824ca 0x40089985 0x4008f535 0x4008a40e 0x40083db2 0x40083e65 0x40083eea 0x4016631d 0x4015de08 0x40154d94 0x400d8081 0x400d80bd 0x400d8165 0x400d81b6 0x400d8242 0x400d8291 0x400d8e55 0x400d8bbd 0x400e054a
0x400d4590: __wrap_esp_panic_handler at C:/PlatformIO/libs/system/reEsp32/src/reEsp32.cpp:483
0x400ecdae: panic_handler at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system\port/panic_handler.c:192
0x40082829: xt_unhandled_exception at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system\port/panic_handler.c:223
0x40083512: _xt_user_exc at xtensa_vectors.o:?
0x400824ca: panic_abort at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system/panic.c:412
0x40089985: esp_system_abort at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system/esp_system.c:135
0x4008f535: __assert_func at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/assert.c:78
0x4008a40e: xQueueGenericSend at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\freertos\FreeRTOS-Kernel/queue.c:828 (discriminator 2)
0x40083db2: lock_release_generic at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:192
0x40083e65: _lock_release at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:198
0x40083eea: __retarget_lock_release at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:334
0x4016631d: __tz_unlock at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/time/tzlock.c:50
0x4015de08: **localtime_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/time/lcltime_r.c:123**
0x40154d94: malloc_timestr_empty at C:/PlatformIO/libs/system/rStrings/src/rStrings.cpp:148
0x400d8081: rSensorItem::asStringTimeValue(sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:550
0x400d80bd: rSensorItem::jsonStringTimeValue(sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:582
0x400d8165: rSensorItem::jsonPartSensorValue(char const*, sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:701
0x400d81b6: rSensorItem::jsonExtremums(char const*, sensor_extremums_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:747
0x400d8242: rSensorItem::jsonValues() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:848
0x400d8291: rSensorItem::jsonNamedValues() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:864
0x400d8e55: rSensorX2::getJSON() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:2155 (discriminator 1)
0x400d8bbd: rSensor::publishData(bool) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:1585
(inlined by) rSensor::publishData(bool) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:1560
0x400e054a: sensorsTaskExec(void*) at C:\PlatformIO\security_v4225/lib/sensors/sensors.cpp:528
Steps to reproduce.
The function that sometimes crashes:
char * malloc_timestr_empty(const char *format, time_t value)
{
if (value > 0) {
struct tm timeinfo;
char buffer[CONFIG_FORMAT_STRFTIME_BUFFER_SIZE];
memset(&buffer, 0, sizeof(buffer));
localtime_r(&value, &timeinfo);
strftime(buffer, sizeof(buffer), format, &timeinfo);
return malloc_string(buffer);
} else {
return malloc_string(CONFIG_FORMAT_EMPTY_DATETIME);
}
}
char * malloc_string(const char *source)
{
if (source) {
uint32_t len = strlen(source);
#if USE_ESP_MALLOC
char *ret = (char*)esp_malloc(len+1);
#else
char *ret = (char*)malloc(len+1);
#endif
if (ret == nullptr) {
rlog_e(tagHEAP, "Failed to create string: out of memory!");
return nullptr;
}
memset(ret, 0, len+1);
strcpy(ret, source);
return ret;
};
return nullptr;
}
Debug Logs.
C:\PlatformIO\security_v4225\ota>c:\Users\kotyara12\.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-addr2line.exe -pfiaC -e c:\PlatformIO\security_v4225\ota\firmware\firmware.elf 0x400d4590 0x400ecdae 0x40082829 0x40083512 0x400824ca 0x40089985 0x4008f535 0x4008a40e 0x40083db2 0x40083e65 0x40083eea 0x4016631d 0x4015de08 0x40154d94 0x400d8081 0x400d80bd 0x400d8165 0x400d81b6 0x400d8242 0x400d8291 0x400d8e55 0x400d8bbd 0x400e054a
0x400d4590: __wrap_esp_panic_handler at C:/PlatformIO/libs/system/reEsp32/src/reEsp32.cpp:483
0x400ecdae: panic_handler at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system\port/panic_handler.c:192
0x40082829: xt_unhandled_exception at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system\port/panic_handler.c:223
0x40083512: _xt_user_exc at xtensa_vectors.o:?
0x400824ca: panic_abort at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system/panic.c:412
0x40089985: esp_system_abort at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\esp_system/esp_system.c:135
0x4008f535: __assert_func at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/assert.c:78
0x4008a40e: xQueueGenericSend at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\freertos\FreeRTOS-Kernel/queue.c:828 (discriminator 2)
0x40083db2: lock_release_generic at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:192
0x40083e65: _lock_release at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:198
0x40083eea: __retarget_lock_release at C:\Users\razzhivinav\.platformio\packages\framework-espidf\components\newlib/locks.c:334
0x4016631d: __tz_unlock at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/time/tzlock.c:50
0x4015de08: **localtime_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/time/lcltime_r.c:123**
0x40154d94: malloc_timestr_empty at C:/PlatformIO/libs/system/rStrings/src/rStrings.cpp:148
0x400d8081: rSensorItem::asStringTimeValue(sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:550
0x400d80bd: rSensorItem::jsonStringTimeValue(sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:582
0x400d8165: rSensorItem::jsonPartSensorValue(char const*, sensor_value_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:701
0x400d81b6: rSensorItem::jsonExtremums(char const*, sensor_extremums_t*) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:747
0x400d8242: rSensorItem::jsonValues() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:848
0x400d8291: rSensorItem::jsonNamedValues() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:864
0x400d8e55: rSensorX2::getJSON() at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:2155 (discriminator 1)
0x400d8bbd: rSensor::publishData(bool) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:1585
(inlined by) rSensor::publishData(bool) at C:/PlatformIO/libs/sensors/reSensor/src/reSensor.cpp:1560
0x400e054a: sensorsTaskExec(void*) at C:\PlatformIO\security_v4225/lib/sensors/sensors.cpp:528
More Information.
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 19 (5 by maintainers)
This is an important fix for stable trees, but the sync to github is so slow this time.
@KaeLL, But, as far as I understood, the same problem was in 4.4.3? But I have no problem on 4.4.3, the devices work for 85 or more days without a single failure. How do I get this fix if it’s already in the public domain? The fact is that ESP-IDF is launched from the PlatformIO package and I don’t know how to randomly load something from the ESP-IDF repository