{"record":{"id":"61d82ffdb9631fa7","repo":"hashicorp/nomad","slug":"only-one-of-cgroups-v1-override-and-cgroups-v2-ove","errorCode":null,"errorMessage":"only one of cgroups_v1_override and cgroups_v2_override may be set","messagePattern":"only one of cgroups_v1_override and cgroups_v2_override may be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/rawexec/driver.go","lineNumber":195,"sourceCode":"\t// * All resource isolation guarantees are lost FOR ALL TASKS if set *\n\tOverrideCgroupV1 hclutils.MapStrStr `codec:\"cgroup_v1_override\"`\n\n\t// OOMScoreAdj sets the oom_score_adj on Linux systems\n\tOOMScoreAdj int `codec:\"oom_score_adj\"`\n\n\t// WorkDir sets the working directory of the task\n\tWorkDir string `codec:\"work_dir\"`\n\n\t//DeniedEnvvars enables the removal of specified environment variables from a given job environment\n\tDeniedEnvvars []string `codec:\"denied_envvars\"`\n}\n\nfunc (t *TaskConfig) validate() error {\n\t// ensure only one of cgroups_v1_override and cgroups_v2_override have been\n\t// configured; must check here because task config validation cannot happen\n\t// on the server.\n\tif len(t.OverrideCgroupV1) > 0 && t.OverrideCgroupV2 != \"\" {\n\t\treturn errors.New(\"only one of cgroups_v1_override and cgroups_v2_override may be set\")\n\t}\n\tif t.OOMScoreAdj < 0 {\n\t\treturn errors.New(\"oom_score_adj must not be negative\")\n\t}\n\tif t.WorkDir != \"\" && !filepath.IsAbs(t.WorkDir) {\n\t\treturn errors.New(\"work_dir must be an absolute path\")\n\t}\n\treturn nil\n}\n\n// TaskState is the state which is encoded in the handle returned in\n// StartTask. This information is needed to rebuild the task state and handler\n// during recovery.\ntype TaskState struct {\n\tReattachConfig *pstructs.ReattachConfig\n\tTaskConfig     *drivers.TaskConfig\n\tPid            int\n\tStartedAt      time.Time","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/rawexec/driver.go#L177-L213","documentation":"The rawexec driver's TaskConfig.validate() rejects task configs that set both cgroups_v1_override (a list of cgroup controllers/paths) and cgroups_v2_override (a single path string). The two overrides target mutually exclusive cgroup hierarchy versions, so specifying both is ambiguous and cannot be validated server-side — it must fail at the client.","triggerScenarios":"Submitting a Nomad job whose rawexec task config includes both cgroups_v1_override (non-empty) and cgroups_v2_override (non-empty string); validate() runs when the client parses the task config before launching.","commonSituations":"Migrating jobs between hosts running cgroup v1 and v2 leaves both fields in the template; copy-paste from old v1 job specs into new v2 ones; operators hedging by setting both hoping the driver picks one.","solutions":["Remove cgroups_v1_override and keep only cgroups_v2_override on hosts running cgroup v2","Remove cgroups_v2_override and keep only cgroups_v1_override on cgroup v1 hosts","Templatize the job (e.g. with Nomad templating or env vars) so only the override matching the host's cgroup version is rendered","Check the host hierarchy (stat -fc %T /sys/fs/cgroup) to decide which single override to keep"],"exampleFix":"// before\nconfig {\n  command = \"/bin/app\"\n  cgroups_v1_override = [\"cpu.max=100000\"]\n  cgroups_v2_override = \"/nomad/app.slice\"\n}\n// after\nconfig {\n  command = \"/bin/app\"\n  cgroups_v2_override = \"/nomad/app.slice\"\n}","handlingStrategy":"validation","validationCode":"func checkCgroupOverrides(cfg TaskConfig) error {\n    if len(cfg.CgroupsV1Override) > 0 && cfg.CgroupsV2Override != \"\" {\n        return errors.New(\"set only one of cgroups_v1_override / cgroups_v2_override\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use templating so only the override matching the host cgroup version is rendered","Audit job specs for both fields when migrating between cgroup v1/v2 hosts","Detect host hierarchy with stat -fc %T /sys/fs/cgroup before choosing an override"],"tags":["rawexec","cgroups","config-validation","nomad"],"backgroundTag":"mutually-exclusive-config-options","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}