-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Logger Recursion Guard per Task on ESP32 #8765
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
Conversation
fixes #esphome/issues#5102 Also fixes a missing recursion_guard_ for ESP8266
This comment was marked as outdated.
This comment was marked as outdated.
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a task-specific recursion guard for the ESP32 logger component to avoid log message loss in multi-task environments. Key changes include:
- Replacing the global recursion guard with separate guards: a dedicated boolean for the main task and pthread TLS for other tasks.
- Updating logging functions in logger.cpp to use the new guard mechanism.
- Configuring ESP-IDF to ensure sufficient thread local storage pointers via init.py.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
esphome/components/logger/logger.h | Replaces the atomic recursion guard with a task-specific implementation using pthread TLS |
esphome/components/logger/logger.cpp | Updates the log functions to check, set, and reset the new recursion guard appropriately |
esphome/components/logger/init.py | Adds configuration to ensure enough thread local storage pointers for the new guard |
Comments suppressed due to low confidence (1)
esphome/components/logger/logger.h:271
- [nitpick] Verify that using a hard-coded TLS key value of 1 does not conflict with other platform keys; consider adding a compile-time check or extended documentation to enforce this constraint.
static const pthread_key_t LOG_RECURSION_KEY = (pthread_key_t) 1;
Thanks for the review, and thanks for catching the TLS issue |
What does this implement/fix?
The previous implementation used a global recursion guard, which caused log messages to be blocked in multi-task environments. To address this, we now leverage pthread thread-local storage (TLS) to track recursion state per task.
Key Changes
pthread_key_create
.Design Highlights
Implementation Notes
pthread_key_create
to dynamically allocate a TLS key.Limitations & Considerations
Testing
Type of change
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml
:# Example config.yaml
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: