hashicorp/nomad · error
MaxRunDuration must be greater than zero
Error message
MaxRunDuration must be greater than zero
What it means
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.
Source
Thrown at nomad/structs/structs.go:7150
if tg.Count < 0 {
mErr = multierror.Append(mErr, errors.New("Task group count can't be negative"))
}
if len(tg.Tasks) == 0 {
// could be a lone consul gateway inserted by the connect mutator
mErr = multierror.Append(mErr, errors.New("Missing tasks for task group"))
}
if tg.Disconnect != nil {
if err := tg.Disconnect.Validate(j); err != nil {
mErr = multierror.Append(mErr, err)
}
}
if tg.MaxRunDuration != nil {
if *tg.MaxRunDuration <= 0 {
mErr = multierror.Append(mErr, errors.New("MaxRunDuration must be greater than zero"))
}
switch j.Type {
case JobTypeBatch, JobTypeSysBatch:
default:
mErr = multierror.Append(mErr, fmt.Errorf("Job type %q does not allow max_run_duration", j.Type))
}
}
for idx, constr := range tg.Constraints {
if err := constr.Validate(); err != nil {
outer := fmt.Errorf("Constraint %d validation failed: %s", idx+1, err)
mErr = multierror.Append(mErr, outer)
}
}
if j.Type == JobTypeSystem {
if tg.Affinities != nil {
mErr = multierror.Append(mErr, fmt.Errorf("System jobs may not have an affinity block"))View on GitHub (pinned to 482b49bf1a)
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.
Example fix
// before
network {
hostname = "my_host"
}
// after
network {
hostname = "my-host"
} Defensive patterns
Strategy: validation
Validate before calling
if net.Hostname != "" && !strings.Contains(net.Hostname, "${") {
if _, ok := dns.IsDomainName(net.Hostname); !ok {
return fmt.Errorf("hostname %q is not a valid DNS name", net.Hostname)
}
} Type guard
func validDNSName(s string) bool {
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])?)*$`)
return re.MatchString(s)
} Prevention
- Use only letters, digits, and hyphens in hostnames
- Prefer interpolation (${...}) for dynamic values
- Validate hostnames in CI before deploying job specs
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- network hostname %q is not a valid DNS name
- failed to build mount for resolv.conf: %v
- failed to build mount for resolv.conf: %v
- Failed to resolve Server RPC advertise address: %v
- error parsing: root should be an object
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/f03f6d6f2b40d929.
Report an issue: GitHub.