{"record":{"id":"f03f6d6f2b40d929","repo":"hashicorp/nomad","slug":"maxrunduration-must-be-greater-than-zero","errorCode":null,"errorMessage":"MaxRunDuration must be greater than zero","messagePattern":"MaxRunDuration must be greater than zero","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7150,"sourceCode":"\n\tif tg.Count < 0 {\n\t\tmErr = multierror.Append(mErr, errors.New(\"Task group count can't be negative\"))\n\t}\n\n\tif len(tg.Tasks) == 0 {\n\t\t// could be a lone consul gateway inserted by the connect mutator\n\t\tmErr = multierror.Append(mErr, errors.New(\"Missing tasks for task group\"))\n\t}\n\n\tif tg.Disconnect != nil {\n\t\tif err := tg.Disconnect.Validate(j); err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tif tg.MaxRunDuration != nil {\n\t\tif *tg.MaxRunDuration <= 0 {\n\t\t\tmErr = multierror.Append(mErr, errors.New(\"MaxRunDuration must be greater than zero\"))\n\t\t}\n\n\t\tswitch j.Type {\n\t\tcase JobTypeBatch, JobTypeSysBatch:\n\t\tdefault:\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"Job type %q does not allow max_run_duration\", j.Type))\n\t\t}\n\t}\n\n\tfor idx, constr := range tg.Constraints {\n\t\tif err := constr.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Constraint %d validation failed: %s\", idx+1, err)\n\t\t\tmErr = multierror.Append(mErr, outer)\n\t\t}\n\t}\n\tif j.Type == JobTypeSystem {\n\t\tif tg.Affinities != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"System jobs may not have an affinity block\"))","sourceCodeStart":7132,"sourceCodeEnd":7168,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7132-L7168","documentation":"When a network stanza declares a hostname, Nomad validates it as a DNS name (unless it contains a ${...} interpolation). A hostname that fails dns.IsDomainName, e.g. containing underscores, spaces, or invalid characters, triggers this error.","triggerScenarios":"Submitting a job whose group network block sets hostname to something like \"my_host\" or \"web server\"; any non-interpolated value that is not a valid domain name.","commonSituations":"Using underscores in hostnames (common mistake); names with spaces or trailing dots from templating; forgetting that interpolated values are skipped but literal ones are validated.","solutions":["Change the hostname to a valid DNS name (letters, digits, hyphens, dot-separated labels).","Use an interpolation like hostname = \"${attr.unique.network.ip-address}\" if dynamic naming is needed.","Validate the name with a DNS regex before submitting the job."],"exampleFix":"// before\nnetwork {\n  hostname = \"my_host\"\n}\n// after\nnetwork {\n  hostname = \"my-host\"\n}","handlingStrategy":"validation","validationCode":"if net.Hostname != \"\" && !strings.Contains(net.Hostname, \"${\") {\n    if _, ok := dns.IsDomainName(net.Hostname); !ok {\n        return fmt.Errorf(\"hostname %q is not a valid DNS name\", net.Hostname)\n    }\n}","typeGuard":"func validDNSName(s string) bool {\n    var re = regexp.MustCompile(`^(?i)[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$`)\n    return re.MatchString(s)\n}","tryCatchPattern":null,"preventionTips":["Use only letters, digits, and hyphens in hostnames","Prefer interpolation (${...}) for dynamic values","Validate hostnames in CI before deploying job specs"],"tags":["nomad","dns","network-validation"],"backgroundTag":"invalid-dns-name","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"}