chenhg5/cc-connect · error
stop scheduled task: %s (%w)
Error message
stop scheduled task: %s (%w)
What it means
stopWindowsTask wraps an error from runPowerShell running its stop-wait-timeout script. The script Stop-ScheduledTask, polls for the task to stop, and calls Write-Error 'scheduled task did not stop within timeout'; exit 1 if it keeps running. The wrapped error thus usually means the task refused to stop within the timeout, or the PowerShell itself failed.
Source
Thrown at daemon/windows.go:243
}
func stopWindowsTask() error {
out, err := runPowerShell(fmt.Sprintf(`
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task) { exit 0 }
if ($task.State -eq 'Running') {
Stop-ScheduledTask -TaskName %s
}
for ($i = 0; $i -lt 20; $i++) {
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task -or $task.State -ne 'Running') { exit 0 }
Start-Sleep -Milliseconds 500
}
Write-Error 'scheduled task did not stop within timeout'
exit 1
`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))
if err != nil {
return fmt.Errorf("stop scheduled task: %s (%w)", out, err)
}
return nil
}
func startWindowsTask() error {
out, err := runPowerShell(fmt.Sprintf(`
$task = Get-ScheduledTask -TaskName %s -ErrorAction SilentlyContinue
if ($null -eq $task) { Write-Error 'scheduled task not found'; exit 1 }
if ($task.State -ne 'Running') { Start-ScheduledTask -TaskName %s }
`, powerShellLiteral(windowsTaskName), powerShellLiteral(windowsTaskName)))
if err != nil {
return fmt.Errorf("start scheduled task: %s (%w)", out, err)
}
return nil
}
func deleteWindowsTask() error {
out, err := runPowerShell(fmt.Sprintf(`View on GitHub (pinned to 4000b2338a)
Solutions
- Inspect the %s output — 'scheduled task did not stop within timeout' means the process hung; kill the cc-connect process manually (Task Manager / Stop-Process).
- Check task state: `Get-ScheduledTask -TaskName <name> | Select State` — if stuck in Stopping, end the underlying process.
- Re-run the operation after the process exits; stopWindowsTask is retried by Install/Uninstall flows.
- Investigate why the agent process hangs (e.g., an active session blocking shutdown).
Example fix
// manually force-stop the process behind the task Get-ScheduledTask -TaskName cc-connect | Select State Stop-Process -Name cc-connect -Force Start-ScheduledTask -TaskName cc-connect # or re-run install/uninstall
Defensive patterns
Strategy: retry
Validate before calling
out, _ := exec.Command("powershell", "-NoProfile", "-Command",
"(Get-ScheduledTask -TaskName '<name>').State").Output()
if strings.TrimSpace(string(out)) == "Running" {
// task still running; ensure it can stop before Stop/Uninstall
} Try / catch
if err := daemon.Stop(); err != nil {
if strings.Contains(err.Error(), "did not stop within timeout") {
// kill the hung process, then retry once
exec.Command("taskkill", "/IM", "cc-connect.exe", "/F").Run()
time.Sleep(time.Second)
err = daemon.Stop()
}
} Prevention
- Ensure the agent process handles termination signals promptly (no long blocking work in shutdown).
- Kill hung processes via Task Manager before retrying stop/uninstall.
- Watch for tasks stuck in 'Stopping' state in Task Scheduler.
When it happens
Trigger: Called by Install, Uninstall, Stop, Restart on Windows when Stop-ScheduledTask fails or the task remains non-stopped after the polling loop (500ms sleeps) expires, causing the script's `exit 1`.
Common situations: The daemon process spawned by the task hangs and ignores termination; the task is stuck in 'Stopping' state in Task Scheduler; waiting on a child process or network I/O; Task Scheduler service unresponsive.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
Related errors
- start existing task: %w
- start task: %w
- register scheduled task: %s (%w)
- start scheduled task: %s (%w)
- delete scheduled task: %s (%w)
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/100a8ddc25e48c32.
Report an issue: GitHub.