dbus-sensors: nvmesensor: add 1s timeout for mi worker cv.wait
The main thread `workerCv.notify_all` function may be called
when mi worker thread is not in waiting state because there is a
small time window between the `io.run()` and the
`std::unique_lock<std::mutex> lock(mtx)` statement.
This corner case is not a big issue after a subsystem is fully
started because there is periodical health poll to notify the
mi worker thread. However, for the `Status::Initializing` state,
this corner case will cause mi worker thread never wake up to
execute handler.
There exist many solutions to fix this problem. The simplest (one line)
fix should be adding 1 second timeout for the `cv.wait`.
Tested:
Reproduce script: https://paste.googleplex.com/5229001098919936
Before the fix, if we keep restarting nvmesensor for hundreds of loops,
we will find that at least one subsystem keeps on printing:
subsystem is intiatilzing, cancel the health poll
processing health data has been cancelled
After the fix, the same restarting test passed hundreds of loops without
printing the message above.
Google-Bug-Id: 310663382
Change-Id: I6493e87d1ee555a8fba581470da503b0c67bec27
Signed-off-by: Jinliang Wang <jinliangw@google.com>
(cherry picked from commit 5e4bce1c1001cb6a73007acf864a80cc85519693)
2 files changed