Various improvements to interactions with user-provided handles#14486
Open
OneBlue wants to merge 5 commits intofeature/wsl-for-appsfrom
Open
Various improvements to interactions with user-provided handles#14486OneBlue wants to merge 5 commits intofeature/wsl-for-appsfrom
OneBlue wants to merge 5 commits intofeature/wsl-for-appsfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves WSLA service handling of user-provided handles by (1) attempting to unblock session termination when operations are using user handles, and (2) reducing access rights when duplicating handles between the service and client processes.
Changes:
- Add
UserHandleRAII + session tracking of in-flight user handles, and invoke cancellation duringWSLASession::Terminate(). - Reduce access rights on duplicated handles (both from caller → service and service → caller) to least-needed flags.
- Add a WSLA test intended to validate cancellation/unblocking behavior for synchronous I/O scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLATests.cpp | Adds a new test covering session termination while a user-handle I/O operation is blocked. |
| src/windows/wslasession/WSLASession.h | Introduces UserHandle and per-session tracking of user handles undergoing I/O. |
| src/windows/wslasession/WSLASession.cpp | Implements UserHandle, OpenUserHandle/ReleaseUserHandle, and termination-time cancellation logic; updates call sites to use reduced-access user handle duplication. |
| src/windows/wslasession/WSLAContainer.cpp | Reduces access when duplicating stdin/stdout/stderr/tty handles back to the client; uses OpenUserHandle for export output. |
| src/windows/common/wslutil.h | Extends DuplicateHandleFromCallingProcess to accept an optional desired access mask. |
| src/windows/common/wslutil.cpp | Implements the desired-access behavior for DuplicateHandleFromCallingProcess. |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/windows/wslasession/WSLASession.cpp:639
- OpenUserHandle is now called from ImportImageImpl/SaveImageImpl, but ImportImage/LoadImage/SaveImage hold m_lock (shared) while calling these helpers. Terminate now takes m_userHandlesLock and then later takes m_lock exclusively; that creates a lock-order inversion (m_lock -> m_userHandlesLock in Import/Save vs m_userHandlesLock -> m_lock in Terminate) and can deadlock during session termination. Consider moving OpenUserHandle calls out of the code paths that execute under m_lock (e.g., open the user handle before acquiring m_lock, or release/reset m_lock before running the long I/O/relay portion, similar to WSLAContainerImpl::Export).
auto lock = m_lock.lock_shared();
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value());
auto requestContext = m_dockerClient->ImportImage(repo, tag.value(), ContentSize);
ImportImageImpl(*requestContext, ImageHandle);
return S_OK;
}
CATCH_RETURN();
void WSLASession::ImportImageImpl(DockerHTTPClient::HTTPRequestContext& Request, ULONG InputHandle)
{
auto userHandle = OpenUserHandle(InputHandle, GENERIC_READ | SYNCHRONIZE);
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value());
auto io = CreateIOContext();
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This change brings improvements to the way the service deals with user handles.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed