Return ERROR_INVALID_STATE if CreateLinuxProcess is invoked while m_processExitThread is not running (#13765)

This commit is contained in:
Blue 2025-11-24 19:32:34 +00:00 committed by GitHub
parent 955cb899ea
commit 47117005db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -324,6 +324,15 @@ void WSLAVirtualMachine::Start()
auto socket = wsl::windows::common::hvsocket::Accept(listenSocket.get(), m_settings.BootTimeoutMs, m_vmTerminatingEvent.get());
m_initChannel = wsl::shared::SocketChannel{std::move(socket), "mini_init", m_vmTerminatingEvent.get()};
// Create a thread to watch for exited processes.
auto [__, ___, childChannel] = Fork(WSLA_FORK::Thread);
WSLA_WATCH_PROCESSES watchMessage{};
childChannel.SendMessage(watchMessage);
THROW_HR_IF(E_FAIL, childChannel.ReceiveMessage<RESULT_MESSAGE<uint32_t>>().Result != 0);
m_processExitThread = std::thread(std::bind(&WSLAVirtualMachine::WatchForExitedProcesses, this, std::move(childChannel)));
ConfigureNetworking();
// Mount the kernel modules VHD.
@ -358,15 +367,6 @@ void WSLAVirtualMachine::Start()
wsl::windows::common::hcs::ModifyComputeSystem(m_computeSystem.get(), wsl::shared::ToJsonW(gpuRequest).c_str());
}
auto [__, ___, childChannel] = Fork(WSLA_FORK::Thread);
WSLA_WATCH_PROCESSES watchMessage{};
childChannel.SendMessage(watchMessage);
THROW_HR_IF(E_FAIL, childChannel.ReceiveMessage<RESULT_MESSAGE<uint32_t>>().Result != 0);
m_processExitThread = std::thread(std::bind(&WSLAVirtualMachine::WatchForExitedProcesses, this, std::move(childChannel)));
ConfigureMounts();
}
@ -802,6 +802,11 @@ CATCH_RETURN();
Microsoft::WRL::ComPtr<WSLAProcess> WSLAVirtualMachine::CreateLinuxProcess(_In_ const WSLA_PROCESS_OPTIONS& Options, int* Errno, const TPrepareCommandLine& PrepareCommandLine)
{
// N.B This check is there to prevent processes from being started before the VM is done initializing.
// to avoid potential deadlocks, since the processExitThread is required to signal the process exit events.
// std::thread::joinable() is const, so this can be called without acquiring the lock.
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_processExitThread.joinable());
auto setErrno = [Errno](int Error) {
if (Errno != nullptr)
{