{"record":{"id":"312d71cf4a27b8da","repo":"cloudflare/cloudflared","slug":"error-during-update-s","errorCode":null,"errorMessage":"Error during update : %s;","messagePattern":"Error during update : (.+?);","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/updater/workers_update.go","lineNumber":250,"sourceCode":"\t}\n\n\tt, err := template.New(\"batch\").Parse(windowsUpdateCommandTemplate)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn t.Execute(f, data)\n}\n\n// run each OS command for windows\nfunc runWindowsBatch(batchFile string) error {\n\tdefer os.Remove(batchFile)\n\tcmd := exec.Command(\"cmd\", \"/C\", batchFile)\n\t_, err := cmd.Output()\n\t// Remove the batch file we created. Don't let this interfere with the error\n\t// we report.\n\tif err != nil {\n\t\tif exitError, ok := err.(*exec.ExitError); ok {\n\t\t\treturn fmt.Errorf(\"Error during update : %s;\", string(exitError.Stderr))\n\t\t}\n\t}\n\treturn err\n}\n","sourceCodeStart":232,"sourceCodeEnd":255,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/updater/workers_update.go#L232-L255","documentation":"cloudflared's Windows service updater (WorkersService) applies an update by running a generated .bat file via `cmd /C`. When cmd.exe exits non-zero, the updater wraps the batch's captured stderr in this error so the user knows why the update failed. It is thrown from runWindowsBatch, called by the WorkersService Apply method during a self-update.","triggerScenarios":"The generated batch file (e.g. stopping the service, copying the new binary, restarting) exits with a non-zero status; cmd.Output() returns *exec.ExitError and the error text is the batch's stderr output.","commonSituations":"The new binary is locked by a running cloudflared process so the copy step fails; insufficient privileges to stop/restart the Windows service; antivirus blocking the batch script; the batch file itself is missing or its path contains quoting problems.","solutions":["Read the stderr text embedded in the message to identify which batch step failed","Stop the cloudflared service manually (net stop cloudflared), apply the update, then restart it","Re-run the update from an elevated (Administrator) command prompt","Check antivirus/EDR logs for blocked script execution and whitelist the batch file","If self-update keeps failing, download and install the new cloudflared MSI manually"],"exampleFix":"// before\n_, err := cmd.Output()\nif err != nil {\n\tif exitError, ok := err.(*exec.ExitError); ok {\n\t\treturn fmt.Errorf(\"Error during update : %s;\", string(exitError.Stderr))\n\t}\n}\n// after\nvar stdout, stderr bytes.Buffer\ncmd.Stdout, cmd.Stderr = &stdout, &stderr\nif err := cmd.Run(); err != nil {\n\tif exitErr, ok := err.(*exec.ExitError); ok {\n\t\treturn fmt.Errorf(\"update batch failed (exit %d): %s\", exitErr.ExitCode(), stderr.String())\n\t}\n\treturn fmt.Errorf(\"failed to run update batch: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// PowerShell pre-check before attempting self-update\nif (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Error 'Update requires elevation'; exit 1 }\nif (Get-Process cloudflared -ErrorAction SilentlyContinue) { Write-Error 'Stop running cloudflared processes first'; exit 1 }","typeGuard":null,"tryCatchPattern":"// Go caller\nif err := update.Apply(); err != nil {\n\tvar exitErr *exec.ExitError\n\tif errors.As(err, &exitErr) {\n\t\tlog.Error().Bytes(\"stderr\", exitErr.Stderr).Msg(\"update batch failed; falling back to manual install\")\n\t}\n\treturn err\n}","preventionTips":["Always run self-update from an elevated prompt","Stop the cloudflared service before updating if it holds the binary open","Whitelist the updater batch file in antivirus/EDR","Prefer MSI installs in managed environments instead of in-place self-update"],"tags":["windows","self-update","process-execution"],"backgroundTag":"command-exit-error","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}