Implement --stop-timeout in wslc create|run and support -1 (infinite) timeouts#40919
Open
OneBlue wants to merge 12 commits into
Open
Implement --stop-timeout in wslc create|run and support -1 (infinite) timeouts#40919OneBlue wants to merge 12 commits into
OneBlue wants to merge 12 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for --stop-timeout in wslc container create/run, including -1 to represent “no timeout”, and plumbs the value through WSLC’s container options, Docker API request/inspect schemas, and the CLI argument layer. It also adds unit/e2e coverage plus localized strings and help text for the new argument.
Changes:
- Add
--stop-timeoutargument handling forwslc container create|run, validation, and help text updates. - Plumb stop-timeout through WSLC container options into Docker create/stop requests and surface it in inspect output.
- Add unit tests and e2e tests covering valid/invalid stop-timeout values (including
-1).
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Adds API-level tests for stop timeout behavior and inspect wiring. |
| test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp | Adds container run e2e tests + help output expectation for --stop-timeout. |
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Adds container create e2e tests + help output expectation for --stop-timeout. |
| src/windows/wslcsession/WSLCContainer.cpp | Validates/forwards stop timeout on create/stop and maps inspect StopTimeout. |
| src/windows/wslcsession/DockerHTTPClient.h | Updates StopContainer signature to accept signed timeout. |
| src/windows/wslcsession/DockerHTTPClient.cpp | Sends signed t= query parameter for stop timeout. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Parses --stop-timeout into container options. |
| src/windows/wslc/services/ContainerService.cpp | Applies parsed stop timeout to WSLCContainerLauncher. |
| src/windows/wslc/services/ContainerModel.h | Adds StopTimeout to ContainerOptions; updates stop default sentinel usage. |
| src/windows/wslc/commands/ContainerRunCommand.cpp | Registers --stop-timeout as a supported run argument. |
| src/windows/wslc/commands/ContainerCreateCommand.cpp | Registers --stop-timeout as a supported create argument. |
| src/windows/wslc/arguments/ArgumentValidation.cpp | Adds integer validation for the stop-timeout argument. |
| src/windows/wslc/arguments/ArgumentDefinitions.h | Defines the stop-timeout argument and localized description hook. |
| src/windows/service/inc/wslc.idl | Introduces stop-timeout constants and adds StopTimeout to WSLCContainerOptions. |
| src/windows/inc/wslc_schema.h | Extends WSLC inspect schema to include StopTimeout. |
| src/windows/inc/docker_schema.h | Extends Docker create/inspect schema to include StopTimeout (and StopSignal in inspect config). |
| src/windows/common/WSLCContainerLauncher.h | Adds stop-timeout setter/state with default sentinel. |
| src/windows/common/WSLCContainerLauncher.cpp | Populates WSLCContainerOptions.StopTimeout from launcher state. |
| src/windows/common/APICompat.cpp | Ensures compat conversion sets StopTimeout to default sentinel. |
| localization/strings/en-US/Resources.resw | Adds localized strings for invalid stop-timeout and CLI arg description. |
| auto container = launcher.Launch(*m_defaultSession); | ||
|
|
||
| auto inspect = container.Inspect(); | ||
| VERIFY_ARE_EQUAL(inspect.Config.StopTimeout.value_or(0), WSLC_STOP_TIMEOUT_NONE); |
| auto container = launcher.Create(*m_defaultSession); | ||
|
|
||
| auto inspect = container.Inspect(); | ||
| VERIFY_ARE_EQUAL(inspect.Config.StopTimeout.value_or(-1), 0); |
| auto container = launcher.Launch(*m_defaultSession); | ||
|
|
||
| auto inspect = container.Inspect(); | ||
| VERIFY_ARE_EQUAL(inspect.Config.StopTimeout.value_or(0), 1); |
| // Wait for at least 2 seconds for the stop to complete to prove that the default 1 second timeout was correctly overriden. | ||
| auto waitResult = WaitForSingleObject(stopThread.native_handle(), 2000); | ||
|
|
||
| VERIFY_ARE_EQUAL(waitResult, WAIT_TIMEOUT); |
Comment on lines
+1435
to
+1438
| ValidateStopTimeout(containerOptions.StopTimeout); | ||
|
|
||
| THROW_HR_IF(E_INVALIDARG, containerOptions.StopTimeout == WSLC_STOP_TIMEOUT_DEFAULT); | ||
| request.StopTimeout = static_cast<int>(containerOptions.StopTimeout); |
Comment on lines
+1022
to
+1024
| const auto inspect = InspectContainer(WslcContainerName); | ||
| VERIFY_IS_FALSE(inspect.Config.StopTimeout.has_value()); | ||
| } |
Comment on lines
+773
to
+775
| const auto inspect = InspectContainer(WslcContainerName); | ||
| VERIFY_IS_FALSE(inspect.Config.StopTimeout.has_value()); | ||
| } |
Comment on lines
238
to
240
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Stop_ValidTimeoutNegativeOne) | ||
| { | ||
| // Run a container in the background | ||
| auto result = RunWslc(std::format(L"container run -d --name {} {} sleep infinity", WslcContainerName, DebianImage.NameAndTag())); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
| const auto containerId = result.GetStdoutOneLine(); | ||
| VERIFY_IS_FALSE(containerId.empty()); | ||
|
|
||
| // Verify container is running | ||
| VerifyContainerIsListed(containerId, L"running"); | ||
|
|
||
| // -1 is a valid timeout value | ||
| result = RunWslc(std::format(L"container stop {} -t -1", containerId)); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| // Verify the container is no longer running | ||
| VerifyContainerIsListed(containerId, L"exited"); | ||
| } | ||
|
|
||
| private: |
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 adds support for --stop-timeout and -1 timeouts (no timeout)
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed