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):
OS: Ubuntu (Modified zephyrprojectrtos/ci:0.26.14 Docker on WSL)
Toolchain: Zephyr SDK 0.16.8
Commit SHA or Version used: Zephyr v3.7.0
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
Describe the bug
In
log_output.c
'sbuffer_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