Skip to content

fix(windows): handle driver reinstalls with active consumers - #216

Open
ReenigneArcher wants to merge 5 commits into
masterfrom
codex/fix-windows-driver-reinstall
Open

ReenigneArcher wants to merge 5 commits into
masterfrom
codex/fix-windows-driver-reinstall

Conversation

@ReenigneArcher

@ReenigneArcher ReenigneArcher commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Description

Reinstalling or upgrading the Windows driver could fail with MSI Error 1722 because the broker was stopped only after the driver update and device restart. Its open device handle could veto the reload, leaving the device pending reboot and causing subsequent restart attempts to fail.

Stop the broker before changing any device and register/start it after the driver update. Skip further device restarts when SetupAPI requires a reboot, and treat PnPUtil's reboot-required or unsupported-restart results as a deferred reload with a warning. Broker reconfiguration uses Win32_Service.Change to preserve the quoted executable path without sc.exe argument parsing, which failed on Windows Server 2022 with exit code 1639. Native stderr is collected before interpreting reboot exit codes in Windows PowerShell 5.1. Other installation failures remain fatal, and a previously running broker is restored if the update fails. Record installation errors before stopping transcription, with a file-log fallback when transcription is unavailable.

Explicitly register SunshineService and sunshine.exe with Windows Installer's Restart Manager before InstallValidate, so running Sunshine instances appear in the standard applications-to-close dialog even though their device handles do not lock MSI-owned files. Use the WiX Util extension for the registrations and document that closing Sunshine ends active streams. Silent installation follows Windows Installer's Restart Manager policy.

Add installed-MSI regression checks for Sunshine shutdown and for repair while a consumer handle is open and the broker is running. Deferred driver reload requirements are recorded as log warnings.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

  • Windows PowerShell 5.1 / Pester 5.9.0, through the required MSYS2/UCRT64 shell: all 136 tests in tests/scripts passed. Regression coverage includes broker shutdown before update/stale-device removal, reboot deferral (exit codes 50 and 3010), fatal update failures, broker restoration, stage-only behavior, fallback error logging, CIM service reconfiguration, and native stderr with reboot exit codes.
  • Ran the modified install script with -WhatIf against the real installed INF, setup helper, and broker paths; passed without changing the installation.
  • Ran scripts/windows/test-installed-driver.ps1 -Verbose; the existing root device was started and the control device opened successfully.
  • PSScriptAnalyzer 1.25.0, actionlint 1.7.12, strict yamllint 1.38.0 using the CI configuration, PowerShell parsing of the CI repair step, and git diff --check: passed.
  • Built the MSI locally with the WiX Util extension and verified its Sunshine resource entries, native Restart Manager dialog, and registration action ordering. The interactive dialog was not manually exercised locally.
  • Installed MSI validation passed in the Windows-MSVC (Windows Server 2022) and Windows-MinGW-UCRT64 CI jobs: initial installation with automatic shutdown of a harmless sunshine.exe fixture, gamepad profile checks, repair with a running broker and an open consumer handle, and uninstall cleanup. Local MSI validation used -WhatIf because the session lacks administrator elevation. CI captures PowerShell Operational errors when file transcription is unavailable.

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
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

Generated with Codex using GPT-6.1 Sol (gpt-6.1-sol), thinking level: xhigh.

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.75%. Comparing base (362333a) to head (a26f564).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
+ Coverage   73.61%   73.75%   +0.14%     
==========================================
  Files          44       44              
  Lines       10705    10735      +30     
  Branches     3651     3651              
==========================================
+ Hits         7880     7918      +38     
- Misses       2428     2439      +11     
+ Partials      397      378      -19     
Flag Coverage Δ
FreeBSD 53.99% <ø> (ø)
Linux-Clang 68.59% <ø> (ø)
Linux-GCC 80.55% <ø> (ø)
PowerShell 78.60% <100.00%> (+2.99%) ⬆️
Windows-MSVC 74.03% <ø> (-0.16%) ⬇️
Windows-MinGW-UCRT64 66.12% <ø> (ø)
macOS 50.94% <ø> (ø)

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

Files with missing lines Coverage Δ
scripts/windows/install-driver.ps1 96.89% <100.00%> (+9.87%) ⬆️

... and 9 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 362333a...a26f564. Read the comment docs.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

None yet

Projects

None yet

1 participant