crowdsecurity/crowdsec · error
duration is required
Error message
duration is required
What it means
CounterType.Validate enforces that a counter bucket has capacity exactly -1 and a non-empty `duration` string. This error is thrown when the counter bucket spec has no duration, meaning the counter would never expire, so validation refuses to build it.
Source
Thrown at pkg/leakybucket/buckettype.go:65
return fmt.Errorf("invalid capacity '%d': must be 0", f.Spec.Capacity)
}
return nil
}
func (TriggerType) BuildProcessors(_ *BucketFactory) []Processor {
return []Processor{&TriggerProcessor{}}
}
type CounterType struct{}
func (CounterType) Validate(f *BucketFactory) error {
if f.Spec.Capacity != -1 {
return fmt.Errorf("invalid capacity '%d': must be -1", f.Spec.Capacity)
}
if f.Spec.Duration == "" {
return errors.New("duration is required")
}
if f.duration <= 0 {
return fmt.Errorf("invalid duration '%d': must be > 0", f.duration)
}
return nil
}
func (CounterType) BuildProcessors(_ *BucketFactory) []Processor {
return []Processor{&DumbProcessor{}}
}
type ConditionalType struct{}
func (ConditionalType) Validate(f *BucketFactory) error {
if f.Spec.Capacity != -1 {
f.logger.Warnf("Using a value different than -1 as capacity for conditional bucket, this may lead to unexpected overflows")View on GitHub (pinned to 909b515798)
Solutions
- Add a valid duration to the counter spec, e.g. `duration: 1m`
- Ensure `capacity: -1` is set as well — Validate rejects any other capacity first
- Check YAML indentation so `duration` sits inside the bucket spec block
- Reload the scenario and confirm the error is gone
Example fix
// before # type: counter # capacity: -1 // after # type: counter # capacity: -1 # duration: 1m
Defensive patterns
Strategy: validation
Validate before calling
// before loading the bucket config
if b.Spec.Type == "counter" {
if b.Spec.Capacity != -1 { return fmt.Errorf("counter capacity must be -1") }
if b.Spec.Duration == "" { return fmt.Errorf("duration is required") }
if _, err := time.ParseDuration(b.Spec.Duration); err != nil { return err }
} Try / catch
if err := CounterType{}.Validate(factory); err != nil {
if strings.Contains(err.Error(), "duration is required") {
return fmt.Errorf("counter bucket %q: add a duration like '1m'", factory.Name)
}
return err
} Prevention
- Remember counter buckets use duration, not leakspeed, when converting from leaky
- Keep capacity: -1 on counter buckets or validation fails earlier
- Lint scenario YAML against the bucket schema before submission
- Test custom scenarios with cscli hubtest before deploying
When it happens
Trigger: Loading a bucket with type: counter whose spec lacks the `duration:` field (f.Spec.Duration == ""), during bucket factory validation.
Common situations: Writing a counter bucket from scratch and forgetting duration; converting a leaky bucket (which uses leakspeed) into a counter without swapping the field; copy-pasted bucket blocks with duration removed.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- leakspeed is required
- a condition is required
- bayesian conditions are required
- invalid prior: must be > 0 and <= 1
- path must start with /
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/5d34d756e9bcf9b1.
Report an issue: GitHub.