Skip to content

Update the VM termination logic to enforce timeouts and avoid hanging if init is stuck during termination#40431

Draft
OneBlue wants to merge 1 commit intomasterfrom
user/oneblue/termination-hang-fix
Draft

Update the VM termination logic to enforce timeouts and avoid hanging if init is stuck during termination#40431
OneBlue wants to merge 1 commit intomasterfrom
user/oneblue/termination-hang-fix

Conversation

@OneBlue
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue commented May 6, 2026

Summary of the Pull Request

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 6, 2026 00:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SocketChannel on Windows to support multiple exit events plus transaction-scoped deadlines, backed by new overlapped socket read/write helpers in relay.*.
  • 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 SocketChannel constructor/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants