-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Automatically add process handle & session termination handle to synchronous IO #14239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/wsl-for-apps
Are you sure you want to change the base?
Changes from all commits
743f52f
c34793c
471b858
441ccd8
af79a67
05f0486
42db6b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,7 +280,7 @@ try | |
|
|
||
| auto requestContext = m_dockerClient->PullImage(repo, tag); | ||
|
|
||
| relay::MultiHandleWait io; | ||
| auto io = CreateIOContext(); | ||
|
|
||
| std::optional<boost::beast::http::status> pullResult; | ||
|
|
||
|
|
@@ -315,7 +315,6 @@ try | |
|
|
||
| auto onCompleted = [&]() { io.Cancel(); }; | ||
|
|
||
| io.AddHandle(std::make_unique<relay::EventHandle>(m_sessionTerminatingEvent.get(), [&]() { THROW_HR(E_ABORT); })); | ||
| io.AddHandle(std::make_unique<DockerHTTPClient::DockerHttpResponseHandle>( | ||
| *requestContext, std::move(onHttpResponse), std::move(onChunk), std::move(onCompleted))); | ||
|
|
||
|
|
@@ -393,7 +392,7 @@ try | |
| ServiceProcessLauncher buildLauncher(buildArgs[0], buildArgs, {}, dockerfileFileHandle ? WSLAProcessFlagsStdin : WSLAProcessFlagsNone); | ||
| auto buildProcess = buildLauncher.Launch(*m_virtualMachine); | ||
|
|
||
| relay::MultiHandleWait io; | ||
| auto io = CreateIOContext(); | ||
|
|
||
| if (dockerfileFileHandle) | ||
| { | ||
|
|
@@ -469,8 +468,6 @@ try | |
|
|
||
| io.AddHandle(std::make_unique<relay::LineBasedReadHandle>(buildProcess.GetStdHandle(2), captureOutput, false)); | ||
|
|
||
| io.AddHandle(std::make_unique<relay::EventHandle>(m_sessionTerminatingEvent.get(), [&]() { THROW_HR(E_ABORT); })); | ||
|
|
||
| io.Run({}); | ||
|
|
||
| int exitCode = buildProcess.Wait(); | ||
|
|
@@ -532,7 +529,7 @@ void WSLASession::ImportImageImpl(DockerHTTPClient::HTTPRequestContext& Request, | |
|
|
||
| THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value()); | ||
|
|
||
| relay::MultiHandleWait io; | ||
| auto io = CreateIOContext(); | ||
|
|
||
| std::optional<boost::beast::http::status> importResult; | ||
|
|
||
|
|
@@ -559,15 +556,12 @@ void WSLASession::ImportImageImpl(DockerHTTPClient::HTTPRequestContext& Request, | |
| } | ||
| }; | ||
|
|
||
| auto onCompleted = [&]() { io.Cancel(); }; | ||
|
|
||
| io.AddHandle(std::make_unique<relay::RelayHandle<relay::ReadHandle>>( | ||
| common::relay::HandleWrapper{std::move(imageFileHandle)}, common::relay::HandleWrapper{Request.stream.native_handle()})); | ||
|
|
||
| io.AddHandle(std::make_unique<relay::EventHandle>(m_sessionTerminatingEvent.get(), [&]() { THROW_HR(E_ABORT); })); | ||
|
|
||
| io.AddHandle(std::make_unique<DockerHTTPClient::DockerHttpResponseHandle>( | ||
| Request, std::move(onHttpResponse), std::move(onProgress), std::move(onCompleted))); | ||
| io.AddHandle( | ||
| std::make_unique<DockerHTTPClient::DockerHttpResponseHandle>(Request, std::move(onHttpResponse), std::move(onProgress)), | ||
| MultiHandleWait::CancelOnCompleted); | ||
|
|
||
| io.Run({}); | ||
|
|
||
|
|
@@ -607,29 +601,27 @@ void WSLASession::ExportContainerImpl(std::pair<uint32_t, wil::unique_socket>& S | |
|
|
||
| THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value()); | ||
|
|
||
| relay::MultiHandleWait io; | ||
|
|
||
| auto onCompleted = [&]() { | ||
| io.Cancel(); | ||
| WSL_LOG("OnCompletedCalledForExport", TraceLoggingValue("OnCompletedCalledForExport", "Content")); | ||
| }; | ||
| auto io = CreateIOContext(); | ||
|
|
||
| std::string errorJson; | ||
| auto accumulateError = [&](const gsl::span<char>& buffer) { | ||
| // If the export failed, accumulate the error message. | ||
| errorJson.append(buffer.data(), buffer.size()); | ||
| }; | ||
|
|
||
| if (SocketCodePair.first != 200) | ||
| { | ||
| io.AddHandle(std::make_unique<relay::ReadHandle>(common::relay::HandleWrapper{std::move(SocketCodePair.second)}, std::move(accumulateError))); | ||
| auto accumulateError = [&](const gsl::span<char>& buffer) { | ||
| // If the export failed, accumulate the error message. | ||
| errorJson.append(buffer.data(), buffer.size()); | ||
| }; | ||
|
|
||
| io.AddHandle( | ||
| std::make_unique<relay::ReadHandle>(common::relay::HandleWrapper{std::move(SocketCodePair.second)}, std::move(accumulateError)), | ||
| MultiHandleWait::CancelOnCompleted); | ||
| } | ||
| else | ||
| { | ||
| io.AddHandle(std::make_unique<relay::RelayHandle<relay::HTTPChunkBasedReadHandle>>( | ||
| common::relay::HandleWrapper{std::move(SocketCodePair.second)}, | ||
| common::relay::HandleWrapper{std::move(containerFileHandle), std::move(onCompleted)})); | ||
| io.AddHandle(std::make_unique<relay::EventHandle>(m_sessionTerminatingEvent.get(), [&]() { THROW_HR(E_ABORT); })); | ||
| io.AddHandle( | ||
| std::make_unique<relay::RelayHandle<relay::HTTPChunkBasedReadHandle>>( | ||
| common::relay::HandleWrapper{std::move(SocketCodePair.second)}, common::relay::HandleWrapper{std::move(containerFileHandle)}), | ||
| MultiHandleWait::CancelOnCompleted); | ||
| } | ||
|
|
||
| io.Run({}); | ||
|
|
@@ -668,25 +660,27 @@ void WSLASession::SaveImageImpl(std::pair<uint32_t, wil::unique_socket>& SocketC | |
|
|
||
| THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value()); | ||
|
|
||
| relay::MultiHandleWait io; | ||
| auto io = CreateIOContext(); | ||
|
|
||
| auto onCompleted = [&]() { io.Cancel(); }; | ||
| std::string errorJson; | ||
| auto accumulateError = [&](const gsl::span<char>& buffer) { | ||
| // If the save failed, accumulate the error message. | ||
| errorJson.append(buffer.data(), buffer.size()); | ||
| }; | ||
|
|
||
| if (SocketCodePair.first != 200) | ||
| { | ||
| io.AddHandle(std::make_unique<relay::ReadHandle>(common::relay::HandleWrapper{std::move(SocketCodePair.second)}, std::move(accumulateError))); | ||
| auto accumulateError = [&](const gsl::span<char>& buffer) { | ||
| // If the save failed, accumulate the error message. | ||
| errorJson.append(buffer.data(), buffer.size()); | ||
| }; | ||
|
|
||
| io.AddHandle( | ||
| std::make_unique<relay::ReadHandle>(common::relay::HandleWrapper{std::move(SocketCodePair.second)}, std::move(accumulateError)), | ||
| MultiHandleWait::CancelOnCompleted); | ||
| } | ||
| else | ||
| { | ||
| io.AddHandle(std::make_unique<relay::RelayHandle<relay::HTTPChunkBasedReadHandle>>( | ||
| common::relay::HandleWrapper{std::move(SocketCodePair.second)}, | ||
| common::relay::HandleWrapper{std::move(imageFileHandle), std::move(onCompleted)})); | ||
| io.AddHandle(std::make_unique<relay::EventHandle>(m_sessionTerminatingEvent.get(), [&]() { THROW_HR(E_ABORT); })); | ||
| io.AddHandle( | ||
| std::make_unique<relay::RelayHandle<relay::HTTPChunkBasedReadHandle>>( | ||
| common::relay::HandleWrapper{std::move(SocketCodePair.second)}, common::relay::HandleWrapper{std::move(imageFileHandle)}), | ||
| MultiHandleWait::CancelOnCompleted); | ||
| } | ||
|
|
||
| io.Run({}); | ||
|
|
@@ -1127,6 +1121,22 @@ HRESULT WSLASession::InterfaceSupportsErrorInfo(REFIID riid) | |
| return riid == __uuidof(IWSLASession) ? S_OK : S_FALSE; | ||
| } | ||
|
|
||
| // TODO consider allowing callers to pass cancellation handles. | ||
|
||
| MultiHandleWait WSLASession::CreateIOContext() | ||
| { | ||
| relay::MultiHandleWait io; | ||
|
|
||
| // Cancel with E_ABORT if the session is terminating. | ||
| io.AddHandle(std::make_unique<relay::EventHandle>( | ||
| m_sessionTerminatingEvent.get(), [this]() { THROW_HR_MSG(E_ABORT, "Session %lu is terminating", m_id); })); | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Cancel with E_ABORT if the client process exits. | ||
| io.AddHandle(std::make_unique<relay::EventHandle>( | ||
| wslutil::OpenCallingProcess(SYNCHRONIZE), [this]() { THROW_HR_MSG(E_ABORT, "Client process has exited"); })); | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return io; | ||
| } | ||
|
|
||
| void WSLASession::OnContainerDeleted(const WSLAContainerImpl* Container) | ||
| { | ||
| std::lock_guard lock{m_lock}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.