Skip to content

Change cpu idle on service and add stop signals - #4578

Open
rasapala wants to merge 7 commits into
mainfrom
CVS-195009_windows_Service
Open

rasapala wants to merge 7 commits into
mainfrom
CVS-195009_windows_Service

Conversation

@rasapala

Copy link
Copy Markdown
Collaborator

🛠 Summary

JIRA CVS-195009
Windows service lifecycle fixes: remove idle spin, fix the startup stop-event race, preserve/report real stop errors, and allow stop during START_PENDING/STOP_PENDING.. Check the WaitForSingleObject return code and report failure if any.

Based on #4568

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Three moderate issues in Windows service lifecycle and error handling remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This pull request improves Windows service lifecycle handling by reducing idle CPU usage, supporting stop requests during pending states, and improving error reporting.

Changes:

  • Replaces busy polling with timed stop-event waits.
  • Initializes stop coordination earlier.
  • Propagates worker and Win32 errors through service status reporting.

Open review items remain in src/main_windows.cpp: handle OVMS_EX_USAGE, initialize the service type before reporting event-creation failures, and recheck the stop flag before publishing RUNNING.

File summaries
File Summary
src/main_windows.hpp Adds atomic lifecycle state and error-reporting declarations.
src/main_windows.cpp Implements event-based waiting, stop handling, and service error propagation; three moderate issues remain.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main_windows.cpp
Comment thread src/main_windows.cpp Outdated
Comment thread src/main_windows.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/main_windows.cpp
DEBUG_LOG("serviceWorkerThread: WaitForSingleObject returned error.");
serviceReportEvent("WaitForSingleObject", waitError);
serviceWorkerWin32Error.store(waitError);
ovmsService->error = static_cast<int>(waitError);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, it serves absolutely no semantic purpose but the presence of this line deliberately introduces a danger of data race because another thread owns ovmsService->error there is absolutely no reason to retain a known data race danger.

Comment thread src/main_windows.cpp

void OvmsWindowsServiceManager::setServiceStopStatusPending() {
serviceStatus.dwControlsAccepted = 0;
serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop is already in progress here, this is not necessary. This isn't harmful but I just find the misunderstanding of windows service lifecycle amusing.

Comment thread src/main_windows.cpp
Comment on lines +592 to 596
if (serviceStopRequested.load()) {
break;
}
// Tell the service controller we are started
OvmsWindowsServiceManager::setServiceRunningStatus();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

despite the check being immediately before the publication, it is still a check-then-act sequence across threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants