Skip to content

ENGINE-1383: Handle Windows exit code 3010 and fix reboot after MCR install#624

Merged
james-nesbitt merged 10 commits into
mainfrom
ENGINE-1383-installps1-update
Apr 30, 2026
Merged

ENGINE-1383: Handle Windows exit code 3010 and fix reboot after MCR install#624
james-nesbitt merged 10 commits into
mainfrom
ENGINE-1383-installps1-update

Conversation

@james-nesbitt
Copy link
Copy Markdown
Collaborator

Summary

Fixes two bugs in the Windows MCR installation path and adds a reliable reboot mechanism.

Bug 1: Exit code 3010 treated as hard failure

When the MCR installer exits with code 3010 (ERROR_SUCCESS_REBOOT_REQUIRED), rig wraps the non-zero exit as ErrCommandFailed. InstallMCR was returning immediately on any non-zero exit, so the reboot-detection logic was unreachable.

Fix: Intercept the error in InstallMCR via isExitCode3010() and treat it as a reboot-required signal instead of a hard failure.

Bug 2: Successful reboot fell through to error return

After a successful rh.Reboot() call, execution fell through to the errRebootRequired return, making every successful reboot appear as a failure.

Fix: Return nil after a successful reboot.

Bug 3: rig's Windows Reboot uses shutdown /r /t 5

rig's Windows.Reboot() issues shutdown /r /t 5 which is silently ignored when Windows has a pending-reboot state (as is the case after a 3010 exit). The host never goes offline and the wait loop times out.

Fix: Override Reboot() on WindowsConfigurer to use Restart-Computer -Force via PowerShell, which bypasses pending-reboot locks.

A TODO comment marks this for upstreaming into k0sproject/rig.

Additional fix: GetInstaller dead code

A dead-code branch in GetInstaller made the installer download path unreachable when no cached path existed.

Fix: Remove the unreachable branch.

Files changed

File Change
pkg/configurer/installer.go Remove dead-code branch blocking installer download
pkg/configurer/common.go Hoist rebootable interface to package scope
pkg/configurer/windows.go Handle exit 3010, fix reboot fall-through, override Reboot() with Restart-Computer -Force

Testing

End-to-end tested against fresh AWS infrastructure (1x Ubuntu 22.04 manager, 3x Windows workers: 2019/2022/2025) using the ENGINE1383 custom installer script.

- installer.go: remove dead-code branch that blocked installer download
  path; GetInstaller() now always attempts the download when no cached
  path exists.

- common.go: hoist rebootable interface to package scope so it is
  accessible from both windows.go and any future configurers.

- windows.go (InstallMCR):
  * Detect exit code 3010 (ERROR_SUCCESS_REBOOT_REQUIRED) via
    isExitCode3010() helper and treat it as a reboot-required signal
    instead of a hard failure.
  * Preserve fallback: if the installer exits 0 but prints
    'Your machine needs to be rebooted', still trigger a reboot.
  * Fix reboot success fall-through: after rh.Reboot() succeeds,
    return nil instead of falling through to the 'host isn't
    rebootable' error return.
rig's Windows Reboot implementation uses 'shutdown /r /t 5' which is
silently ignored when Windows has a pending-reboot state (e.g. after an
MCR install that exits 3010). Override Reboot() on WindowsConfigurer to
use PowerShell's Restart-Computer -Force which bypasses pending-reboot
locks and reliably triggers the restart.

TODO: move this fix upstream into k0sproject/rig.
@james-nesbitt
Copy link
Copy Markdown
Collaborator Author

The unit tests did not fail, but rather the unit test tear down failed after the tests passed.

shutdown /r /t 0 returns immediately (exit 0) before Windows has begun
tearing down its network stack. waitForHost starts polling right after
Reboot() returns, so all 60 echo probes (3s apart) succeed before the
host ever drops WinRM — the offline window is never observed.

Adding a 15-second sleep gives Windows time to start its shutdown
sequence so the subsequent waitForHost(false) poll loop actually catches
the host going offline.
The /f flag forces running applications to close, which is necessary on
Windows Server 2025 where processes can block a pending reboot. Without
it, 'shutdown /r /t 0' completes but the host never actually reboots.
AWS EC2 WinRM sessions run under a filtered Administrator token that
lacks SeShutdownPrivilege. 'shutdown /r /f /t 0' succeeds (exit 0) but
is silently ignored because the token has insufficient privilege.

Fix: create a one-shot scheduled task running as SYSTEM (which always
holds SeShutdownPrivilege) and trigger it immediately. SYSTEM-context
tasks bypass the WinRM token restriction and reliably trigger the
reboot.
/sc once /st 00:00 causes schtasks to write a warning to stderr when
the scheduled time is in the past. Rig treats any stderr output as an
error, causing Reboot() to fail even though the task was created
successfully. /sc onstart requires no start time and creates the task
silently.
Each worker locked mutex at entry (line 106) and deferred unlock (line
107), then attempted a second mutex.Lock() on the error path (line 114).
The second lock deadlocked the goroutine since it already held the mutex.
workerpool.StopWait() then blocked forever waiting for the deadlocked
worker to finish.

Fix: remove the outer lock/defer and only lock when recording an error,
using an early-return guard so only the first error is kept.
The schtask is scheduled with /sc onstart, meaning it fires on every
system startup. Without cleanup, the task triggers a second reboot when
the machine comes back up after the MCR-install reboot, causing
docker swarm join (and any subsequent operation) to fail because the
host reboots again mid-flight.

Delete the task immediately after rh.Reboot() returns (machine is back
up and WinRM is reconnected) to prevent it from firing on subsequent
startups.
The ONSTART schtask fires on every startup, causing repeated reboots.
The post-reboot cleanup in InstallMCR is too late -- the task has already
triggered a second reboot by the time the cleanup runs.

Fix: use /t 5 (5-second countdown) so the task can be deleted immediately
after it is triggered but before the OS actually executes the shutdown.
This prevents the task from re-firing on subsequent startups.

The post-reboot cleanup in InstallMCR is kept as a fallback in case the
pre-delete fails (e.g. the WinRM session is dropped in the 5s window).
Copy link
Copy Markdown

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

Fixes multiple issues in the Windows Mirantis Container Runtime (MCR) install/reboot path (reboot-required exit code handling, reboot fall-through, and a more reliable reboot implementation), and removes dead code that prevented installer downloads.

Changes:

  • Treat Windows installer exit code 3010 as “reboot required” and return nil after a successful reboot.
  • Replace/override Windows reboot behavior with a scheduled-task-driven restart approach and task cleanup.
  • Remove dead branch in GetInstaller that made the download path unreachable.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
pkg/docker/image.go Adjusts parallel image pull error handling (but introduces a return-value timing issue; see comment).
pkg/configurer/windows.go Handles exit code 3010, fixes reboot fall-through, and adds a Windows reboot implementation plus cleanup.
pkg/configurer/installer.go Removes unreachable early-return to allow installer download; concurrency concern remains (see comment).
pkg/configurer/common.go Hoists rebootable interface to package scope for reuse.
Comments suppressed due to low confidence (1)

pkg/configurer/installer.go:32

  • downloadedInstallers is a package-level map accessed without synchronization. GetInstaller is called from Windows install/uninstall paths that run across hosts in parallel, so concurrent reads/writes can panic with "concurrent map read and map write". Protect this cache with a sync.Mutex/sync.RWMutex, use sync.Map, or remove the global cache and let callers manage caching.
func GetInstaller(source string) (string, error) {
	path, ok := downloadedInstallers[source]
	if ok {
		return path, nil
	}

	path, getErr := downloadInstaller(source)
	if getErr != nil {
		return "", fmt.Errorf("%w, installer download failed; %s", ErrInstallerDownloadFailed, getErr.Error())
	}
	downloadedInstallers[source] = path
	return path, nil

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/docker/image.go
Comment thread pkg/configurer/windows.go
Comment thread pkg/configurer/windows.go
Comment thread pkg/configurer/windows.go
Comment thread pkg/configurer/windows.go
@smerkviladze
Copy link
Copy Markdown

@james-nesbitt Overall, it looks good. Could you please address the Copilot review comments?

pkg/docker/image.go:
- Fix StopWait() race: call wp.StopWait() explicitly before reading
  lastError instead of deferring it. A deferred StopWait() evaluates
  the return expression before workers finish, potentially returning
  nil when a worker later records an error.

pkg/configurer/windows.go:
- isExitCode3010: tighten match string from '3010' to
  'non-zero exit code: 3010' to avoid false positives on error messages
  that incidentally contain those digits.
- Reboot: fix comment '/t 0' -> '/t 5' to match the actual command.
- Reboot: update top-level comment to describe the actual schtask
  mechanism; remove stale reference to Restart-Computer -Force from
  an earlier iteration.
@james-nesbitt james-nesbitt force-pushed the ENGINE-1383-installps1-update branch from b61c7a0 to 78d209d Compare April 28, 2026 10:05
@james-nesbitt
Copy link
Copy Markdown
Collaborator Author

All CoPilot issues resolved.

@james-nesbitt
Copy link
Copy Markdown
Collaborator Author

I realized that I need to run one more test, but using the current/existing install.ps1 to see if we have broken anything.

@james-nesbitt
Copy link
Copy Markdown
Collaborator Author

james-nesbitt commented Apr 28, 2026

Regression test for the older install.ps1 passed without concern.

The only CoPilot suggestion that was not exactly addressesd was: #624 (comment)

This is ready for final review (@smerkviladze )

Copy link
Copy Markdown

@smerkviladze smerkviladze left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@james-nesbitt james-nesbitt merged commit 2a00b0f into main Apr 30, 2026
11 checks passed
@james-nesbitt james-nesbitt deleted the ENGINE-1383-installps1-update branch April 30, 2026 09:45
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.

3 participants