{"record":{"id":"bd3915502a53439d","repo":"hashicorp/nomad","slug":"invalid-max-template-event-rate-given","errorCode":null,"errorMessage":"Invalid max template event rate given","messagePattern":"Invalid max template event rate given","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/taskrunner/template/template.go","lineNumber":166,"sourceCode":"\n// Validate validates the configuration.\nfunc (c *TaskTemplateManagerConfig) Validate() error {\n\tif c == nil {\n\t\treturn fmt.Errorf(\"Nil config passed\")\n\t} else if c.UnblockCh == nil {\n\t\treturn fmt.Errorf(\"Invalid unblock channel given\")\n\t} else if c.Lifecycle == nil {\n\t\treturn fmt.Errorf(\"Invalid lifecycle hooks given\")\n\t} else if c.Events == nil {\n\t\treturn fmt.Errorf(\"Invalid event hook given\")\n\t} else if c.ClientConfig == nil {\n\t\treturn fmt.Errorf(\"Invalid client config given\")\n\t} else if c.TaskDir == \"\" {\n\t\treturn fmt.Errorf(\"Invalid task directory given: %q\", c.TaskDir)\n\t} else if c.EnvBuilder == nil {\n\t\treturn fmt.Errorf(\"Invalid task environment given\")\n\t} else if c.MaxTemplateEventRate == 0 {\n\t\treturn fmt.Errorf(\"Invalid max template event rate given\")\n\t}\n\n\t// Once is a runner config, but in Nomad it is set per template, so all\n\t// templates given to a runner should have the same value for Once.\n\tvar once bool\n\tfor i, t := range c.Templates {\n\t\tif i == 0 {\n\t\t\tonce = t.Once\n\t\t} else if t.Once != once {\n\t\t\treturn fmt.Errorf(\"All templates should have same Once value\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (c *TaskTemplateManagerConfig) OnceModeEnabled() bool {\n\treturn len(c.Templates) > 0 && c.Templates[0].Once","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/taskrunner/template/template.go#L148-L184","documentation":"Validate() rejects a config whose MaxTemplateEventRate is the zero time.Duration. This rate limiter bounds how often template change events are emitted to the task runner; zero would either disable or break throttling, so an explicit positive value is required.","triggerScenarios":"Calling NewTaskTemplateManager with a config that never sets MaxTemplateEventRate (leaves the zero value time.Duration), or explicitly sets it to 0.","commonSituations":"Tests or tooling constructing TaskTemplateManagerConfig manually without copying the client's template event rate; config plumbing refactors that drop the client MaxTemplateEventRate setting.","solutions":["Set MaxTemplateEventRate to the client's configured value (e.g. from config.MaxTemplateEventRate) before calling NewTaskTemplateManager.","If the client config value is unset, default it to a sane positive duration (Nomad default: 1s / time.Second) instead of leaving it zero.","Guard constructors that copy client config so this field is always propagated."],"exampleFix":"// before\ncfg := &template.TaskTemplateManagerConfig{\n    TaskDir: taskDir,\n    EnvBuilder: eb,\n}\n// after\ncfg := &template.TaskTemplateManagerConfig{\n    TaskDir: taskDir,\n    EnvBuilder: eb,\n    MaxTemplateEventRate: clientConfig.MaxTemplateEventRate, // e.g. time.Second\n}","handlingStrategy":"validation","validationCode":"if cfg == nil || cfg.MaxTemplateEventRate <= 0 {\n    return fmt.Errorf(\"template manager config needs a positive MaxTemplateEventRate\")\n}","typeGuard":"func hasRate(c *template.TaskTemplateManagerConfig) bool { return c != nil && c.MaxTemplateEventRate > 0 }","tryCatchPattern":"tm, err := template.NewTaskTemplateManager(cfg)\nif err != nil {\n    return fmt.Errorf(\"creating template manager: %w\", err)\n}","preventionTips":["Propagate MaxTemplateEventRate from the client config whenever building this struct.","Apply a default (e.g. time.Second) at client config load time so it is never zero downstream.","Never construct the struct field-by-field in ad-hoc code; use a helper."],"tags":["config","validation","nomad-client","rate-limit"],"backgroundTag":"missing-required-argument","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"}