Skip to content

Avoid stop service race window during uninstall - #40625

Merged
Feng Wang (chemwolf6922) merged 3 commits into
masterfrom
user/chemwolf6922/avoid-race-window-in-stop-service
Jun 1, 2026
Merged

Feng Wang (chemwolf6922) merged 3 commits into
masterfrom
user/chemwolf6922/avoid-race-window-in-stop-service

Conversation

@chemwolf6922

@chemwolf6922 Feng Wang (chemwolf6922) commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

There is a race window in the ServiceControl StopService action. Where the service can be started again by a wsl call. This causes the stop service step to stuck when docker desktop is open.
This PR adds a custom action to disable the service before stopping it to avoid this race window. Add also adds a custom action to revert (enable the service) on failure.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 22, 2026 06:54

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.

Pull request overview

This PR addresses an uninstall-time race where WSLService can be reactivated (e.g., via wsl / COM activation) while MSI is trying to stop it, potentially causing the StopServices step to hang (notably when Docker Desktop is open). It adds MSI custom actions to disable the service before stopping it and re-enable it on rollback.

Changes:

  • Export new MSI custom actions from wslinstall.dll: DisableWslService and EnableWslService.
  • Implement service start-type toggling via ChangeServiceConfigW in the installer DLL.
  • Sequence new deferred/rollback custom actions before StopServices during full uninstall.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/windows/wslinstall/wslinstall.def Exports DisableWslService / EnableWslService from wslinstall.dll.
src/windows/wslinstall/DllMain.cpp Adds helper to change WSLService start type and implements the new custom actions.
msipackage/package.wix.in Defines and sequences the new deferred + rollback custom actions before StopServices on uninstall.

Comment thread msipackage/package.wix.in
Comment thread src/windows/wslinstall/DllMain.cpp
@benhillis

Copy link
Copy Markdown
Member

I think this looks like a good approach, Blue (@OneBlue) let's discuss.

@chemwolf6922
Feng Wang (chemwolf6922) marked this pull request as ready for review May 26, 2026 02:28
@chemwolf6922
Feng Wang (chemwolf6922) requested a review from a team as a code owner May 26, 2026 02:28
@OneBlue

Copy link
Copy Markdown
Collaborator

Thank you for doing this Feng Wang (@chemwolf6922).
Do we have logs / dumps of what the installer is doing when we hit this "stuck" state ?

The StopServices action should be immediately followed by DeleteServices, which should delete the service. Do we know which of those actions is stuck ?

@chemwolf6922

Copy link
Copy Markdown
Contributor Author

Hi Blue (@OneBlue) I shared the log internally.

@OneBlue Blue (OneBlue) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. It's wild that MSI doesn't do that on its own, but this change should be relatively low risk and a clear improvement.

Thank you for root causing this !

@chemwolf6922
Feng Wang (chemwolf6922) merged commit c28bd15 into master Jun 1, 2026
12 checks passed
@chemwolf6922
Feng Wang (chemwolf6922) deleted the user/chemwolf6922/avoid-race-window-in-stop-service branch June 1, 2026 02:14
Ben Hillis (benhillis) pushed a commit that referenced this pull request Sep 8, 2026
Disable service before stopping service during uninstall.

(cherry picked from commit c28bd15)
Ben Hillis (benhillis) added a commit that referenced this pull request Sep 10, 2026
* Validate NUL-termination of flexible-array Buffer in interop messages (#40402)

* Validate NUL-termination of flexible-array Buffer in interop messages

Use string::FromMessageBuffer<T>() instead of directly accessing the
Buffer[] flexible-array member in interop message structs. FromMessageBuffer
validates that a NUL terminator exists within the span bounds, preventing
out-of-bounds reads when a malformed message contains no Buffer data or
lacks NUL termination.

Affected message handlers:
- LxInitMessageQueryEnvironmentVariable (config.cpp)
- LxInitMessageCreateLoginSession (config.cpp)
- LxMiniInitMessageUnmount (main.cpp)

Co-authored-by: Copilot <[email protected]>

* Remove unused Message parameter name in WSLC_UNMOUNT handler

After switching to FromMessageBuffer, the Message parameter is no longer
referenced directly. Remove the name to avoid -Wunused-parameter.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Ben Hillis <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit 909d5eb)

* Bind KdRelay to loopback (#41260)

Restrict the KdRelay listener to local connections.

Co-authored-by: Copilot <[email protected]>

Co-authored-by: Ben Hillis <[email protected]>
Copilot-Session: d9d1a097-a7bc-4c1b-806b-d3778adfd23a
(cherry picked from commit 5eb2138)

* Update Microsoft.NETCore.App.Runtime to 10.0.11 (#41332)

(cherry picked from commit 8edd976)

* Fix unvalidated TerminalProfileSize during distribution import (#41495)

* Fix unvalidated TerminalProfileSize when importing a distribution

_ProcessImportResultMessage constructed the terminal profile string_view
using the message-supplied TerminalProfileSize without validating it
against the received buffer length. Use the bounds-checked two-argument
span::subspan() overload (matching the existing ShortcutIconSize handling
a few lines above) so an inconsistent size value throws instead of
producing a string_view that runs past the end of the buffer.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 35281c30-3d08-4f05-8c84-2ce4711023d5

* format source

---------

Co-authored-by: Ben Hillis <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 35281c30-3d08-4f05-8c84-2ce4711023d5
(cherry picked from commit f2d87e0)

* Avoid stop service race window during uninstall (#40625)

Disable service before stopping service during uninstall.

(cherry picked from commit c28bd15)

---------

Co-authored-by: Ben Hillis <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Blue <[email protected]>
Co-authored-by: Feng Wang <[email protected]>
Copilot-Session: d9d1a097-a7bc-4c1b-806b-d3778adfd23a
Copilot-Session: 35281c30-3d08-4f05-8c84-2ce4711023d5
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.

Cannot start WSL: Wsl/Service/CreateInstance/CreateVm/HCS/ERROR_FILE_NOT_FOUND

4 participants