-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
Describe the bug
Due to the current implementation, if the logging thread is configured with a higher priority than other threads that produce log messages at a lower priority, there is a possibility that the logging thread can starve those lower-priority threads indefinitely.
In some scenarios, users may have expensive tasks that take a considerable amount of time to execute. In such cases, it is reasonable to increase the priority of the logging thread in order to observe log messages while those tasks are running.
It is important to note that this issue can only occur when there are also higher-priority threads producing log messages. The following scenario illustrates the problem.
- P(A) < P(L) < P(B)
- L is the logging thread
-
Thread A
Callsz_log_msg_enqueue()and reachesmsg_alloc(), but is interrupted by Thread B, which has higher priority. The message has not yet been committed. -
Thread B
Preempts Thread A, callsz_log_msg_enqueue(), and reachesmsg_commit(), causingz_log_msg_post_finalize()to be called. -
Thread L
Callsz_impl_log_process()and attempts to claim Thread A’s message. Since the message has not yet been committed,z_log_msg_claim()returnsNULL.
Next,z_log_msg_pending()is called and returnstruebecause the message is still present in the buffer but not committed. At this point, an endless loop begins. -
Thread L (repeats)
Callsz_impl_log_process()again, attempts to claim Thread A’s message, receivesNULLfromz_log_msg_claim(), andz_log_msg_pending()continues to returntrue. -
And so on…
From this point onward, the logging thread becomes stuck in a tight loop and prevents lower-priority threads from ever being scheduled, resulting in indefinite starvation.
Regression
- This is a regression.
Steps to reproduce
Create a sample application with two log-producing threads: one running at a higher priority than the logging thread and one running at a lower priority. During execution, the logging thread eventually becomes stuck in an infinite loop.
Relevant log output
Impact
Intermittent – Occurs occasionally; hard to reproduce.
Environment
N/A
Additional Context
This problem was already reported in the following discussion #68289