Skip to content

fix(windows): fail fast when the broker service is not installed - #149

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
Se7enbrc:fix/broker-service-fail-fast
Sep 21, 2026
Merged

ReenigneArcher merged 4 commits into
LizardByte:masterfrom
Se7enbrc:fix/broker-service-fail-fast

Conversation

@Se7enbrc

Copy link
Copy Markdown
Contributor

Description

On a Windows host running the current release and prerelease without the Virtual HID Driver installed, every broker request blocks for the 5 s retry deadline. connect_to_broker_pipe treats ERROR_FILE_NOT_FOUND from CreateFileA as "the broker is still starting" and retries every 10 ms for 5000 ms, but when the libvirtualhid_broker service was never installed the pipe can never appear.

Sunshine calls lvh::get_license_status() on its input thread at every controller arrival, which is the 5 s input hold in LizardByte/Sunshine#5759.

This change asks the Service Control Manager once, on the first ERROR_FILE_NOT_FOUND, whether the broker service exists.

If OpenServiceW fails with ERROR_SERVICE_DOES_NOT_EXIST, the connect fails immediately with that error instead of spending the deadline. Any other answer (service manager can't be opened, access denied, service present) keeps the existing retry behaviour, so a broker that is genuinely starting is still waited for.

The check runs on the first attempt only so a starting broker isn't hit with an SCM lookup every 10 ms, and the path that works is unchanged.

An installed-but-stopped service still waits as before; a restart passes through STOPPED and the wait is what makes that case succeed. make_unique_service_handle moved up a few lines so the new helper can use it.

Measured on a Windows 11 host with the driver package uninstalled, timing get_license_status() from a small test program: 7998 / 8015 / 8048 ms before, 0 / 0 / 0 ms after, and the error text goes from "The system cannot find the file specified" to "The specified service does not exist as an installed service".
With the service present the call takes 0–21 ms before and after.

Tests: two new fixture scenarios, pipe_service_missing (service absent: 1 create attempt, 0 sleeps) and pipe_service_manager_unavailable (SCM can't be opened: the deadline is still honoured), and the existing pipe retry rows now account for the extra service-manager and service handles the check opens and closes.

WindowsBrokerClientTest passes 7/7 with and without the change; the rest of the suite shows the same pre-existing device-creation failures on this machine either way.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@CLAassistant

CLAassistant commented Sep 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Se7enbrc

Copy link
Copy Markdown
Contributor Author

@ReenigneArcher apologies I filed the issue on the sunshine repo, not here where it belonged

@ReenigneArcher

Copy link
Copy Markdown
Member

@Se7enbrc no worries, thanks for the PR!

@Se7enbrc

Copy link
Copy Markdown
Contributor Author

@ReenigneArcher fixed the sonarcloud quality finding

@cgutman

cgutman commented Sep 20, 2026 •

Copy link
Copy Markdown

If you're not starting the broker service manually or via trigger start, you should probably check to see if the service is running too, otherwise you'll have this same issue if the service is stopped/disabled for some reason.

@Se7enbrc

Copy link
Copy Markdown
Contributor Author

@cgutman good catch, verified against latest prerelease, fix pushed with doc stub

@ReenigneArcher
ReenigneArcher force-pushed the fix/broker-service-fail-fast branch from 8b1dbf1 to 95522e5 Compare September 21, 2026 00:16
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.99%. Comparing base (02fe328) to head (95522e5).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/windows/windows_broker_client.cpp 96.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
+ Coverage   73.98%   73.99%   +0.01%     
==========================================
  Files          40       40              
  Lines       10085    10107      +22     
  Branches     3536     3544       +8     
==========================================
+ Hits         7461     7479      +18     
- Misses       1952     2299     +347     
+ Partials      672      329     -343     
Flag Coverage Δ
FreeBSD 52.49% <ø> (ø)
Linux-Clang 55.38% <ø> (ø)
Linux-GCC 66.17% <ø> (+0.03%) ⬆️
PowerShell 75.60% <ø> (ø)
Windows-MSVC 88.53% <95.65%> (-0.10%) ⬇️
Windows-MinGW-UCRT64 63.74% <91.30%> (+0.12%) ⬆️
macOS 49.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/windows/windows_broker_client.cpp 93.54% <96.00%> (+0.31%) ⬆️

... and 12 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02fe328...95522e5. Read the comment docs.

@ReenigneArcher
ReenigneArcher merged commit 513882f into LizardByte:master Sep 21, 2026
34 checks passed
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.

Controller arrival stalls all input ~5 s on 2026.906+ when the Virtual HID Driver broker isn't installed

4 participants