crowdsecurity/crowdsec · error

while parsing bouncers api auto-delete duration: %w

Error message

while parsing bouncers api auto-delete duration: %w

What it means

StartFlushScheduler parses bouncers_gc.api with cstime.ParseDurationWithDays to schedule deletion of bouncers authenticated via API keys. An unparseable duration string yields this wrapped error and stops startup.

Source

Thrown at pkg/database/flush.go:105

		if config.AgentsGC.Api != nil {
			c.Log.Warning("agents auto-delete for API auth is not supported (use cert or login_password)")
		}
	}

	if config.BouncersGC != nil {
		if config.BouncersGC.Cert != nil {
			duration, err := cstime.ParseDurationWithDays(*config.BouncersGC.Cert)
			if err != nil {
				return nil, fmt.Errorf("while parsing bouncers cert auto-delete duration: %w", err)
			}

			config.BouncersGC.CertDuration = &duration
		}

		if config.BouncersGC.Api != nil {
			duration, err := cstime.ParseDurationWithDays(*config.BouncersGC.Api)
			if err != nil {
				return nil, fmt.Errorf("while parsing bouncers api auto-delete duration: %w", err)
			}

			config.BouncersGC.ApiDuration = &duration
		}

		if config.BouncersGC.LoginPassword != nil {
			c.Log.Warning("bouncers auto-delete for login/password auth is not supported (use cert or api)")
		}
	}

	_, err = scheduler.NewJob(
		gocron.DurationJob(flushInterval),
		gocron.NewTask(c.FlushAgentsAndBouncers, ctx, config.AgentsGC, config.BouncersGC),
		gocron.WithSingletonMode(gocron.LimitModeReschedule),
	)
	if err != nil {
		return nil, fmt.Errorf("while starting FlushAgentsAndBouncers scheduler: %w", err)
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Fix the api key to a valid duration, e.g. api: 30d or api: 168h.
  2. Use only supported units: Go duration units (ns..h) or 'd'.
  3. Quote the YAML value to avoid parsing surprises, e.g. api: "30d".
  4. Remove the key to disable bouncer API-key GC.

Example fix

// before
bouncers_gc:
  api: 1mo

// after
bouncers_gc:
  api: "30d"
Defensive patterns

Strategy: validation

Validate before calling

if cfg.BouncersGC != nil && cfg.BouncersGC.Api != "" {
    if _, err := cstime.ParseDurationWithDays(cfg.BouncersGC.Api); err != nil {
        return fmt.Errorf("bouncers_gc.api: %w", err)
    }
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "bouncers api") {
        // reject/fix the bouncers_gc.api value
    }
    return err
}

Prevention

When it happens

Trigger: config.BouncersGC.Api holds a value ParseDurationWithDays cannot handle — unitless number, unknown suffix, or malformed duration.

Common situations: Config like api: 1mo under api.server.gc.bouncers_gc; trailing whitespace or stray characters in the YAML value.

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/6b354efd6cab111d. Report an issue: GitHub.