Update the VM termination logic to enforce timeouts and avoid hanging if init is stuck during termination#40431
Draft
Update the VM termination logic to enforce timeouts and avoid hanging if init is stuck during termination#40431
Conversation
… init is stuck during session termination
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors WSLC/WSL socket-channel cancellation and timeout handling so VM/session teardown can stop waiting on init-side communication instead of hanging indefinitely. It primarily affects WSLC session termination, shared socket I/O plumbing, and the Windows/Linux init channel call sites that use that plumbing.
Changes:
- Extends
SocketChannelon Windows to support multiple exit events plus transaction-scoped deadlines, backed by new overlapped socket read/write helpers inrelay.*. - Threads the session-terminating event through WSLC VM channels and adds a termination-time path that reduces init-channel timeouts during shutdown.
- Updates Windows service/session call sites to use the new
SocketChannelconstructor/transaction API and adjusts WSLC init signal handling.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/wslcsession/WSLCVirtualMachine.h |
Adds session-termination event plumbing and an init-channel timeout field/API. |
src/windows/wslcsession/WSLCVirtualMachine.cpp |
Applies new timeout/cancellation behavior across VM init, fork, signal, unmount, and crash-dump paths. |
src/windows/wslcsession/WSLCSession.cpp |
Wires the session event into VM creation and changes termination sequencing/process-stop behavior. |
src/windows/wslcsession/WSLCProcessControl.cpp |
Updates tty control channel construction for the new exit-event vector API. |
src/windows/wslcsession/DockerHTTPClient.cpp |
Adjusts Docker client channel construction to the new exit-event vector form. |
src/windows/service/exe/WslCoreVm.cpp |
Converts service-side mini-init/crash-dump/helper channels to the new constructor shape. |
src/windows/service/exe/WslCoreInstance.cpp |
Moves instance-stop transactions to transaction-scoped deadlines. |
src/windows/service/exe/LxssUserSession.cpp |
Updates telemetry channel construction for the new socket-channel API. |
src/windows/service/exe/LxssCreateProcess.h |
Switches create-process transactions to deadline-based timeout handling. |
src/windows/common/relay.hpp |
Declares new overlapped socket message read/write handle types. |
src/windows/common/relay.cpp |
Implements reusable socket overlapped I/O helpers and shared cancellation cleanup. |
src/windows/common/GnsPortTrackerChannel.cpp |
Updates GNS port-tracker channel construction to the new API. |
src/windows/common/GnsChannel.cpp |
Updates GNS channel construction to the new API. |
src/windows/common/DnsTunnelingChannel.cpp |
Updates DNS tunneling channel construction to the new API. |
src/shared/inc/SocketChannel.h |
Introduces multi-exit-event support, transaction deadlines, and new Windows send/receive internals. |
src/linux/init/WSLCInit.cpp |
Changes Linux-side WSLC signal handling during init message processing. |
|
|
||
| return std::make_tuple(pid, ptyMaster, wsl::shared::SocketChannel{std::move(socket), std::to_string(pid), m_vmTerminatingEvent.get()}); | ||
| return std::make_tuple( | ||
| pid, ptyMaster, wsl::shared::SocketChannel{std::move(socket), std::to_string(pid), {m_vmTerminatingEvent.get(), m_sessionTerminatingEvent}}); |
| THROW_HR_IF_MSG(E_FAIL, pid <= 0, "fork() returned %i", pid); | ||
|
|
||
| auto socket = wsl::windows::common::hvsocket::Connect(m_vmId, port, m_vmTerminatingEvent.get(), m_bootTimeoutMs); | ||
| auto socket = wsl::windows::common::hvsocket::Connect(m_vmId, port, m_vmTerminatingEvent.get(), m_initChannelTimeout); |
Comment on lines
+669
to
+670
| std::this_thread::sleep_for(std::chrono::milliseconds( | ||
| 100000000)); // Small delay to increase the chance that the target process is waiting in a syscall and can be interrupted by the signal. |
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
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed