zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.77k stars 6.57k forks source link

RTT Log Backend stuck in infinite loop #79235

Open harristomy opened 3 weeks ago

harristomy commented 3 weeks ago

Describe the bug

In log_output.c's buffer_write function, the while loop can be infinite if a logging backend returns only the number of bytes it has written (rather than failed to write or process).

The return behaviour is not consistent across different backends. For example, the UART backend just returns the length of the buffer if it was passed, and no information is retained on how many bytes were successfully/unsuccessfully written, only the length of the input buffer is returned.

Whereas RTT will return 0 bytes written or all bytes written. In the case of a backend that behaves like RTT, the buffer_write will be stuck in an infinite loop due to constantly returning zero bytes written.

To Reproduce Use a logging backend that only returns the number of bytes successfully written and force it to fail to write any.

Expected behavior Consistent return behaviour across all backends implemented. I haven't checked the other backends, so this might be unique to RTT?

Impact Lack of logs

Logs and console output

No logs output due to thread being stuck in infinite loop while processing a backend like RTT

Environment (please complete the following information):

Suggested fix Basic rudimentary fix could be to limit the number of retries for a particular buffer write and then exit the loop if it fails too many retry attempts

github-actions[bot] commented 3 weeks ago

Hi @harristomy! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙