Skip to content

Conversation

@Vincent-Dalstra
Copy link
Contributor

@Vincent-Dalstra Vincent-Dalstra commented Aug 22, 2025

Description

There are two commits: the first fixes the actual issue I encountered, while the second eleminates two redundant checks for NULL, discovered while investigating the issue.

(1) Previously, esp_log_router_flash_vprintf() would wait up to 100ms for a mutex, but if the mutex was still not available it would still enter the critical section, and panic when it attempted to return the mutex.

Removing the timeout gets us the desired behaviour.

(2) In addition, it could also enter the critical section without taking the mutex if the mutex handle was NULL. While in practice this is almost impossible, it still doesn't make any sense. Better to make it actually impossible, and eliminate these null checks entirely.

Related

Fixes #564

Testing

Tested with the same hardware and software where I initially found issue #564

Before applying these changes, the problem would occur shortly after boot with approximately 50% chance.

After, the issue stopped. It also does not hang or trigger the watchdog.


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant
Copy link

CLAassistant commented Aug 22, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Aug 22, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello Vincent-Dalstra, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 944a2eb

@github-actions github-actions bot changed the title fix(log_router): Do not enter critical section until mutex is taken fix(log_router): Do not enter critical section until mutex is taken (AEGHB-1190) Aug 22, 2025
@YanKE01
Copy link
Contributor

YanKE01 commented Aug 22, 2025

Hi, @Vincent-Dalstra , thanks for your contribution. In addition to modifying the code, please also update the component version under components/utilities/log_router:

  1. change the version in idf_component.yml to 0.1.1,
  2. add a bug fix description in the ChangeLog.md

esp_err_t esp_log_router_to_file(const char* file_path, const char* tag, esp_log_level_t level)
{
// Create mutex for thread safety
g_log_router_mutex = xSemaphoreCreateMutex();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutex should be ensured to be initialized only once, because esp_log_router_to_file needs to support routing to different files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching that. Fixed: [62f8dd4]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also changed the failure message from ESP_LOGW, to ESP_LOGE, to reflect its severity.


First release version.

## v0.1.1 - 2025-08-25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please place the latest changes at the top, i.e., before ## v0.1.0 - 2025-7-1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad. Fixed: [adb014e]

@YanKE01
Copy link
Contributor

YanKE01 commented Aug 28, 2025

LGTM! It would be better to adjust it into a single commit. @leeebo ,please add MR TAG

Wait as long as it takes to acquire the mutex (previously, it would only
wait 100ms for the mutex before entering the critical section anyway!)

fix(log_router): ensure mutex is created successfully, or else return an error

Check if the mutex (which ensures thread safety) was created
successfully, and return an error if it wasn't. Moved this check to the
top of the function, so that it doesn't need to clean up memory in the
case of failure.

Since successfully creating the mutex is now a precondition for creating
the list, we can safely remove the NULL checks when using the mutex.
@Vincent-Dalstra
Copy link
Contributor Author

Thank you. I've squashed it all into 944a2eb

Copy link
Collaborator

@leeebo leeebo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vincent-Dalstra LGTM! Thanks for your contribution!

@leeebo
Copy link
Collaborator

leeebo commented Aug 29, 2025

sha=944a2eb0d82a7a40b90b411b4cc3cead774a2675

@zhanzhaocheng zhanzhaocheng merged commit cb40f88 into espressif:master Sep 12, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic_abort when using log_router (AEGHB-1189)

5 participants