wslc service com api support for emit warning message as optional com callback#40558
wslc service com api support for emit warning message as optional com callback#40558yao-msft wants to merge 16 commits into
Conversation
OneBlue
left a comment
There was a problem hiding this comment.
I like this structure because it will nicely integrate with the EMIT_USER_WARNING() macros that we have.
Sadly there's one tricky that we need to consider: If the caller doesn't read from the handle, we need to be able to Cancel the IO so that we don't get stuck when trying to terminate a session if the caller doesn't read from the HANDLE and the pipe gets full.
(This is how we do it on the regular session handles
The issue would be the same if we decided to use a COM callback, we would need to keep track of the callback, and cancel it if the session terminates (pointer to how we terminate COM callbacks today
One way we could make this work would be by adding a pointer to the WSLCSession to COMServiceExecutionContext, and do something like this:
HRESULT WSLCSession::CreateContainer(const WSLCContainerOptions* containerOptions, IWSLCContainer** Container)
{
COMServiceExecutionContext context(this);
[...]
}
So that way, we can register the COM callback / IO with the session when we emit a warning, and so it will be correctly cancelled if the session terminates.
Regarding the pipe vs COM callback, I think I have a small preference for the COM callback, since we already do that in other places (like for the pull / build callbacks), and at least it won't force the caller to create a thread if no warning are emitted
38f0edb to
bc55b39
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new IWarningCallback COM callback and threads warning emission through WSLC session/container operations, so non-fatal issues (e.g., recovery failures, Docker warnings) can be surfaced to callers instead of only being logged.
Changes:
- Adds a new
IWarningCallbackinterface and plumbs an optional callback parameter through many WSLC COM APIs and their implementations. - Introduces
WSLCExecutionContextto routeEMIT_USER_WARNING(...)to the callback (with lazy COM cancellation registration). - Adds localized warning strings and new tests that validate warning callback delivery during container/volume recovery scenarios.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Updates call sites for new optional callback parameters; adds warning-callback tests for recovery paths. |
| test/windows/wslc/e2e/WSLCE2EHelpers.cpp | Updates session creation to pass the new optional warning callback argument. |
| test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp | Updates session creation calls to include the optional warning callback argument. |
| test/windows/PluginTests.cpp | Updates session/image calls for new optional warning callback parameters. |
| test/windows/Common.cpp | Updates LoadTestImage to pass the new optional warning callback argument. |
| src/windows/wslcsession/WSLCVolumes.cpp | Emits user warnings on volume recovery/release failures. |
| src/windows/wslcsession/WSLCSessionFactory.h | Extends factory CreateSession signature to accept IWarningCallback. |
| src/windows/wslcsession/WSLCSessionFactory.cpp | Passes IWarningCallback through to WSLCSession::Initialize. |
| src/windows/wslcsession/WSLCSession.h | Extends WSLC session COM methods to accept optional IWarningCallback parameters; adds IsUserCOMCallbackRegistered(). |
| src/windows/wslcsession/WSLCSession.cpp | Switches to WSLCExecutionContext and emits warnings for various non-fatal failure paths and Docker warnings. |
| src/windows/wslcsession/WSLCExecutionContext.h | New execution context that forwards EMIT_USER_WARNING to IWarningCallback with cancellation support. |
| src/windows/wslcsession/WSLCContainer.h | Extends Start to accept optional IWarningCallback; threads session reference into wrapper. |
| src/windows/wslcsession/WSLCContainer.cpp | Uses WSLCExecutionContext and emits warnings for additional container-related failure scenarios and Docker warnings. |
| src/windows/WslcSDK/wslcsdk.cpp | Updates SDK internal calls to pass nullptr for the new warning-callback parameters. |
| src/windows/wslc/services/WarningCallback.h | Adds a CLI-side IWarningCallback implementation that writes warnings to stderr. |
| src/windows/wslc/services/SessionService.cpp | Updates session creation/enter calls for new optional warning callback parameter (currently passing nullptr). |
| src/windows/wslc/services/ImageService.cpp | Updates image operations to pass nullptr for the new optional warning callback parameter. |
| src/windows/wslc/services/ContainerService.cpp | Updates container start calls to pass nullptr for the new optional warning callback parameter. |
| src/windows/service/inc/wslc.idl | Defines IWarningCallback and adds optional callback parameters to multiple existing COM interfaces/methods. |
| src/windows/service/exe/WSLCSessionManager.h | Extends session manager signatures to accept optional IWarningCallback. |
| src/windows/service/exe/WSLCSessionManager.cpp | Plumbs IWarningCallback through to session factory creation and enter-session flow. |
| src/windows/common/WSLCContainerLauncher.cpp | Updates container creation/start calls for new optional warning callback parameters. |
| localization/strings/en-US/Resources.resw | Adds new localized warning strings for recovery and other warning scenarios. |
OneBlue
left a comment
There was a problem hiding this comment.
This approach looks great and integrate nicely into our existing warning infrastructure.
I think the next step would be to add logic to print the warnings on stderr in wslc, and this should be ready to merge
Summary of the Pull Request
Added IWarningCallback to COM api that may emit warning messages. Scanned through wslcsession to add warning messages as applicable.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Added 2 tests that test the warning callback where we can create a warning situation deterministically. Other places we do not have a deterministic way to get to the warning state.