You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes a startup race in the WSLC SDK. In an Event-mode container, an output callback that runs during WslcStartContainer, before ioCallbacks is published, could release the container. The callback could also run before the WinRT init Process had its handle attached. Callbacks now stay dormant until ownership is published and handles are attached.
PR Checklist
Closes: Link to issue #xxx
Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
Tests: Added/updated if needed and all pass
Localization: All end user facing strings can be localized
Dev docs: Added/updated if needed
Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx
Detailed Description of the Pull Request / Additional comments
The IOCallback constructor started its worker thread, and that thread delivered callbacks right away. Startup could therefore interleave like this:
A callback calls WslcReleaseContainer (or WinRT Close()). The IO-thread guard sees no ioCallbacks yet, so it lets the native container be freed.
WslcStartContainer continues and assigns ioCallbacks into freed memory.
In WinRT, the init Process (the callback context) can be destroyed before its handle is attached.
Validation Steps Performed
New test WslcSdkTests::ReleaseContainerFromIOCallbackDuringStart: the output callback releases the container during start. It expects ERROR_INVALID_HANDLE_STATE and the container to still be running.
New test WslcSdkWinRtTests::EventModeInitProcessAttachedBeforeOutputCallback: the first OutputReceived handler uses the init process. It expects the handle to already be attached.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical close-during-activation race can destroy the WinRT Process context while the output worker is still alive, requiring a lifetime fix and regression coverage for closing before Start() returns.
This PR addresses WSLC SDK startup races by deferring I/O callbacks until ownership is published and, for WinRT containers, the init-process handle is attached.
Changes:
Add explicit callback activation and cancellation handling for inactive workers.
Introduce internal startup entry points to coordinate native and WinRT initialization.
Add regression tests for callback-triggered release and init-process handle readiness.
File
Description
test/windows/wslc/WslcSdkWinRTTests.cpp
Test init-process handle readiness during output callbacks.
test/windows/wslc/WslcSdkTests.cpp
Test rejection of container release from a startup callback.
src/windows/WslcSDK/WslcsdkInternal.h
Declare deferred-start and callback-activation entry points.
src/windows/WslcSDK/wslcsdk.def
Export internal entry points by ordinal.
src/windows/WslcSDK/wslcsdk.cpp
Publish callback ownership and process handles before activation.
src/windows/WslcSDK/winrt/Container.cpp
Activate callbacks after attaching the init-process handle.
src/windows/WslcSDK/IOCallback.h
Declare activation support and its synchronization event.
src/windows/WslcSDK/IOCallback.cpp
Gate callback delivery and handle inactive-worker cleanup.
src/windows/WslcSDK/CMakeLists.txt
Include the new internal header in the SDK target.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical exec-process lifetime race allows WslcReleaseProcess to return while a callback is still executing, risking use-after-free of the callback context; explicit cancellation and joining plus a regression test are needed.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical lifecycle issues remain: releasing an init-process alias cancels shared container callbacks, and closing from an output callback can free context still used by the worker, causing use-after-free.
Callback-thread Close clears init-process ownership after release is rejected
src/windows/WslcSDK/winrt/Container.cpp:88
The first OutputReceived handler can still call container.Close() on the callback thread: native release rejects this, but Container::Close() ignores the failure and clears m_initProcess. Without an external process reference, this destroys the raw callback context while the worker remains alive, leaving subsequent callbacks to access freed memory. Preserve ownership when release is rejected or defer teardown off the callback thread, and add a same-thread-close test without retaining an external InitProcess reference.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate potential indefinite blocking and data races involving callback shutdown and independently released container and process handles.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Releasing the init-process handle before deferred callback activation cancels the container-owned worker, causing later activation to deliver neither buffered output nor onExit.
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to add it here because it never gets passed to the runtime
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Fixes a startup race in the WSLC SDK. In an Event-mode container, an output callback that runs during
WslcStartContainer, beforeioCallbacksis published, could release the container. The callback could also run before the WinRT initProcesshad its handle attached. Callbacks now stay dormant until ownership is published and handles are attached.PR Checklist
Detailed Description of the Pull Request / Additional comments
The
IOCallbackconstructor started its worker thread, and that thread delivered callbacks right away. Startup could therefore interleave like this:WslcReleaseContainer(or WinRTClose()). The IO-thread guard sees noioCallbacksyet, so it lets the native container be freed.WslcStartContainercontinues and assignsioCallbacksinto freed memory.Process(the callback context) can be destroyed before its handle is attached.Validation Steps Performed
WslcSdkTests::ReleaseContainerFromIOCallbackDuringStart: the output callback releases the container during start. It expectsERROR_INVALID_HANDLE_STATEand the container to still be running.WslcSdkWinRtTests::EventModeInitProcessAttachedBeforeOutputCallback: the firstOutputReceivedhandler uses the init process. It expects the handle to already be attached.