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

Memory leaking when logging with EspLogger #285

Closed
kagetsuki1997 opened this issue Aug 18, 2023 · 1 comment
Closed

Memory leaking when logging with EspLogger #285

kagetsuki1997 opened this issue Aug 18, 2023 · 1 comment

Comments

@kagetsuki1997
Copy link

kagetsuki1997 commented Aug 18, 2023

I found out that the heap allocated bytes keep increasing when logging with EspLogger, then the program will crash when there is no free heap to use. I use heap_caps_get_info to observe the heap status.
Here are the dependencies

[dependencies]
log = { version = "0.4.17", default-features = false }
esp-idf-sys = { version = "0.33", default-features = false }
esp-idf-hal = { version = "0.41", optional = true, default-features = false }
esp-idf-svc = { version = "0.46", optional = true, default-features = false }
embedded-svc = { version = "0.25", optional = true, default-features = false }
embedded-hal = "=1.0.0-alpha.10"
ESP_IDF_VERSION: release/v5.1
Board type: nodemcu-32s

I did some tests and simulate on Wokwi, it seems like the problem is from fwrite https://github.com/esp-rs/esp-idf-svc/blob/master/src/log.rs#L15C1-L24
If we comment this part of code, then there is no memory issue.
If the slice length is less than 4, there there is no memory issue too. It's very weird.

        unsafe {
            let slice = "log\n".as_bytes();
            fwrite(slice.as_ptr() as *const _, 1, slice.len() as u32, stdout);
        }

Can anyone help to take a look what's the problem in EspLogger?
Thanks.

[UPDATE]
I remove a log of a task which run every 10ms, then it seems the memory issue doesn't occur.
Maybe we shouldn't log too fast or make too many logs?

@Vollbrecht
Copy link
Collaborator

Did you send your logs through uart?(E.g the default log channel) You may were constrained by the throughput there and logs just kept on pilling up. In that case there is not to much we can do.

I close this issue for now as it doesn't have any immediate actionable item. Feel free to reopen it if you stumble on a related problem again. Thanks!

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

No branches or pull requests

2 participants