fix: Improve output loop error handling in MSWindowsWatchdog
Prevents high CPU usage while waiting for data (ERROR_NO_DATA)
This commit is contained in:
parent
5ea8d0326a
commit
162cb85811
1 changed files with 5 additions and 14 deletions
|
|
@ -337,24 +337,15 @@ void MSWindowsWatchdog::outputLoop(void *)
|
||||||
while (m_running) {
|
while (m_running) {
|
||||||
const BOOL ok = ::ReadFile(m_outputReadPipe, raw, kBufSize, &bytesRead, nullptr);
|
const BOOL ok = ::ReadFile(m_outputReadPipe, raw, kBufSize, &bytesRead, nullptr);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok || bytesRead == 0) {
|
||||||
const DWORD err = ::GetLastError();
|
const DWORD err = ::GetLastError();
|
||||||
if (err == ERROR_BROKEN_PIPE) {
|
if (err != NO_ERROR && err != ERROR_NO_DATA) {
|
||||||
// It doesn't make sense to keep reading the pipe if the process has exited and closed its end of the pipe.
|
LOG_WARN("could not read from output pipe, error: %s", windowsErrorToString(err).c_str());
|
||||||
LOG_DEBUG("output pipe closed, exiting output loop");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retry immediately when we get a transient error like ERROR_NO_DATA (pipe is non-blocking).
|
// Retry immediately when nothing to read or we get a transient error like ERROR_NO_DATA (pipe is non-blocking).
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesRead == 0) {
|
|
||||||
// Sleep for short moment so we're not busy looping while the Core is quiet (which is the case most of the time).
|
|
||||||
// Important: Keep the sleep short so the service can shut down fast.
|
|
||||||
Arch::sleep(0.1);
|
Arch::sleep(0.1);
|
||||||
LOG_DEBUG("no more data to read from output pipe");
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString decoded =
|
const QString decoded =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue