{"record":{"id":"e6fb2afa4763176b","repo":"argoproj/argo-workflows","slug":"error-stopping-workflow-s-w","errorCode":null,"errorMessage":"error stopping workflow %s: %w","messagePattern":"error stopping workflow (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/cron/operator.go","lineNumber":306,"sourceCode":"\t\t}\n\t}\n\treturn true, nil\n}\n\nfunc (woc *cronWfOperationCtx) terminateOutstandingWorkflows(ctx context.Context) error {\n\tfor _, wfObjectRef := range woc.cronWf.Status.Active {\n\t\twoc.log.WithField(\"name\", wfObjectRef.Name).Info(ctx, \"stopping\")\n\t\terr := util.TerminateWorkflow(ctx, woc.wfClient, wfObjectRef.Name)\n\t\tif err != nil {\n\t\t\tif apierrors.IsNotFound(err) {\n\t\t\t\twoc.log.WithField(\"name\", wfObjectRef.Name).Warn(ctx, \"workflow not found when trying to terminate outstanding workflows\")\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif alreadyShutdownErr, ok := errors.AsType[util.AlreadyShutdownError](err); ok {\n\t\t\t\twoc.log.Warn(ctx, alreadyShutdownErr.Error())\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"error stopping workflow %s: %w\", wfObjectRef.Name, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (woc *cronWfOperationCtx) runOutstandingWorkflows(ctx context.Context) (bool, error) {\n\tmissedExecutionTime, err := woc.shouldOutstandingWorkflowsBeRun(ctx)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tif !missedExecutionTime.IsZero() {\n\t\twoc.run(ctx, missedExecutionTime)\n\t\treturn true, nil\n\t}\n\treturn false, nil\n}\n\nfunc (woc *cronWfOperationCtx) shouldOutstandingWorkflowsBeRun(ctx context.Context) (time.Time, error) {","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/cron/operator.go#L288-L324","documentation":"terminateOutstandingWorkflows (used by the Replace concurrency policy) stops each active Workflow listed in the CronWorkflow's Status.Active via util.TerminateWorkflow. If termination fails for a workflow — and it is neither a NotFound (already gone) nor an AlreadyShutdownError — the error is wrapped with the workflow name and aborts the cron run.","triggerScenarios":"TerminateWorkflow returns an error while patching shutdown (e.g. RBAC denial on workflow update/patch, API server conflict or timeout, workflow already terminating with a conflicting patch) for a workflow referenced in cronWf.Status.Active.","commonSituations":"CronWorkflow's controller service account lacking update permission on workflows; API server flakiness under load; stale Status.Active entries pointing at workflows in a bad state; concurrent shutdown by another actor.","solutions":["Check the inner wrapped error for the root cause (RBAC vs conflict vs timeout)","Ensure the controller's service account can patch/update workflows in the namespace","Verify Status.Active is accurate; manually stop orphaned workflows with argo stop <name>","Retry — conflicts and transient API errors usually resolve on the next cron tick"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"kubectl auth can-i patch workflows.argoproj.io --as=system:serviceaccount:<ns>:<controller-sa> -n <ns>","typeGuard":"// tolerate benign termination errors, fail on real ones\nif apierrors.IsNotFound(err) { continue }\nif _, ok := errors.AsType[util.AlreadyShutdownError](err); ok { continue }\nreturn fmt.Errorf(\"error stopping workflow %s: %w\", wfObjectRef.Name, err)","tryCatchPattern":"err := util.TerminateWorkflow(ctx, woc.wfClient, name)\nif err != nil {\n    if apierrors.IsNotFound(err) || errors.AsType[util.AlreadyShutdownError](err) != nil {\n        continue // already gone or already shutting down\n    }\n    return fmt.Errorf(\"error stopping workflow %s: %w\", name, err)\n}","preventionTips":["Grant the controller SA update/patch on workflows","Clean stale Status.Active references with argo stop or manual patch","Retry on the next cron tick for transient API conflicts"],"tags":["cron","workflow-shutdown","rbac","kubernetes"],"backgroundTag":"workflow-stop-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}