Skip to content

fix(initsystem): don't fail WinSCM start/stop/restart on benign slow-start warning#408

Open
vikramhh wants to merge 1 commit into
k0sproject:mainfrom
vikramhh:fix/winscm-benign-start-warning
Open

fix(initsystem): don't fail WinSCM start/stop/restart on benign slow-start warning#408
vikramhh wants to merge 1 commit into
k0sproject:mainfrom
vikramhh:fix/winscm-benign-start-warning

Conversation

@vikramhh

Copy link
Copy Markdown

On a Windows target, WinSCM.StartService/StopService/RestartService run
Start-Service/Stop-Service/Restart-Service with only -ErrorAction Stop.
When a service stays in StartPending/StopPending for a moment (common on a cold
first start doing real init work), PowerShell emits a non-terminating warning:

WARNING: Waiting for service '<display> (<name>)' to start...

That warning goes to the warning stream, which lands on stderr under a
subprocess. rig treats any Windows stderr output as a failure
(cmd.ErrWroteStderr) unless AllowWinStderr is set, so a successful-but-slow
start is reported as command wrote output to stderr. The command exits 0 and
the service does reach Running — only the benign warning trips the failure.
(The executor already sets $ProgressPreference='SilentlyContinue', which
covers the progress stream but not the warning stream.)

Fix: add -WarningAction SilentlyContinue to the three cmdlets. This silences
exactly the benign progress warning while -ErrorAction Stop still turns a
genuine failure into a terminating (non-zero) error, so real error detection is
preserved. Per review on the issue, this uses -WarningAction only and does
not set AllowWinStderr, which would be a blunt instrument that greenlights
any stderr output and could mask unexpected diagnostics.

EnableService/DisableService use Set-Service, which doesn't wait on a
state transition and so doesn't emit this warning — left unchanged.

Existing winscm_test.go success cases now also assert the flag is present;
they fail on the pre-fix code and pass after. go vet/gofmt clean.

Fixes #404

…start warning

When a Windows service stays in StartPending/StopPending for a moment (common
on a cold first start), Start-Service/Stop-Service/Restart-Service emit a
non-terminating "Waiting for service '...' to start/stop..." warning. That goes
to the warning stream, which lands on stderr under a subprocess, and rig treats
any Windows stderr output as a failure (ErrWroteStderr) unless AllowWinStderr is
set. So a successful-but-slow start was reported as a failure.

Add -WarningAction SilentlyContinue to the three cmdlets. This silences exactly
the benign progress warning while -ErrorAction Stop still turns a genuine
failure into a terminating (non-zero) error, so real error detection is
preserved. Uses -WarningAction only, not AllowWinStderr, which would greenlight
any stderr output and could mask unexpected diagnostics.

Fixes k0sproject#404

Signed-off-by: Vikram bir Singh <vsingh@mirantis.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vikramhh
vikramhh force-pushed the fix/winscm-benign-start-warning branch from 328ea8b to 7066c3c Compare July 23, 2026 15:42
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.

WinSCM.StartService fails on slow/cold start: benign StartPending warning trips ErrWroteStderr

1 participant