{"record":{"id":"5c0f61e176e488ee","repo":"crowdsecurity/crowdsec","slug":"while-parsing-agents-cert-auto-delete-duration-w","errorCode":null,"errorMessage":"while parsing agents cert auto-delete duration: %w","messagePattern":"while parsing agents cert auto-delete duration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/flush.go","lineNumber":72,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t_, err = scheduler.NewJob(\n\t\tgocron.DurationJob(1*time.Minute),\n\t\tgocron.NewTask(c.FlushAlerts, ctx, time.Duration(config.MaxAge), maxItems),\n\t\tgocron.WithSingletonMode(gocron.LimitModeReschedule),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"while starting FlushAlerts scheduler: %w\", err)\n\t}\n\n\t// Init & Start cronjob every hour for bouncers/agents\n\tif config.AgentsGC != nil {\n\t\tif config.AgentsGC.Cert != nil {\n\t\t\tduration, err := cstime.ParseDurationWithDays(*config.AgentsGC.Cert)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"while parsing agents cert auto-delete duration: %w\", err)\n\t\t\t}\n\n\t\t\tconfig.AgentsGC.CertDuration = &duration\n\t\t}\n\n\t\tif config.AgentsGC.LoginPassword != nil {\n\t\t\tduration, err := cstime.ParseDurationWithDays(*config.AgentsGC.LoginPassword)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"while parsing agents login/password auto-delete duration: %w\", err)\n\t\t\t}\n\n\t\t\tconfig.AgentsGC.LoginPasswordDuration = &duration\n\t\t}\n\n\t\tif config.AgentsGC.Api != nil {\n\t\t\tc.Log.Warning(\"agents auto-delete for API auth is not supported (use cert or login_password)\")\n\t\t}\n\t}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/flush.go#L54-L90","documentation":"StartFlushScheduler parses the agents_gc.cert duration from config using cstime.ParseDurationWithDays, which accepts both Go durations and day-suffixed values (e.g. '30d'). This error wraps the parse failure and aborts scheduler startup.","triggerScenarios":"config.AgentsGC.Cert is set to a string that ParseDurationWithDays cannot parse — missing unit (e.g. '30'), unknown suffix, negative value, or malformed syntax like '1.5d' if unsupported.","commonSituations":"Typo in config/config.yaml under api.server.gc.agents_gc.cert, e.g. cert: 3months (month unit not supported) or cert: 3600 without a unit.","solutions":["Fix the value in config.yaml: use Go duration units (h, m, s) or 'd' for days, e.g. cert: 30d or cert: 720h.","Remember 'd' (days) is supported via ParseDurationWithDays but units like 'w', 'mo', 'y' are not — convert them to days or hours.","Validate the config with cscli before restarting: cscli config check (or start crowdsec and read the wrapped error).","Remove the key entirely to disable agent cert GC if no value is desired."],"exampleFix":"// config.yaml\n// before\napi:\n  server:\n    gc:\n      agents_gc:\n        cert: 3months\n\n// after\napi:\n  server:\n    gc:\n      agents_gc:\n        cert: 90d","handlingStrategy":"validation","validationCode":"func validDurationWithDays(s string) error {\n    _, err := cstime.ParseDurationWithDays(s)\n    return err\n}\n// before startup:\nif err := validDurationWithDays(cfg.AgentsGC.Cert); err != nil {\n    return fmt.Errorf(\"agents_gc.cert: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := c.StartFlushScheduler(ctx, flushCfg); err != nil {\n    var pe *time.ParseError\n    if errors.As(err, &pe) || strings.Contains(err.Error(), \"parsing agents cert\") {\n        // fix or reject the config value\n    }\n    return err\n}","preventionTips":["Only use Go duration units (h, m, s) or plain day suffix 'd' in gc settings.","Quote duration values in YAML to avoid type surprises.","Validate the whole config at deploy time with a config check before restarts."],"tags":["go","config","duration","crowdsec"],"backgroundTag":"invalid-duration-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}