{"record":{"id":"07677c0940490885","repo":"crowdsecurity/crowdsec","slug":"controller-init-w","errorCode":null,"errorMessage":"controller init: %w","messagePattern":"controller init: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/apiserver.go","lineNumber":548,"sourceCode":"\t\t\treturn errors.New(\"plugins are enabled, but config_paths.plugin_dir is not defined\")\n\t\t}\n\n\t\terr := pluginBroker.Init(ctx, cConfig.PluginConfig, s.cfg.Profiles, cConfig.ConfigPaths)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"plugin broker: %w\", err)\n\t\t}\n\n\t\tlog.Info(\"initiated plugin broker\")\n\t\ts.AttachPluginBroker(pluginBroker)\n\t}\n\n\treturn nil\n}\n\nfunc (s *APIServer) InitController() error {\n\terr := s.controller.Init()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"controller init: %w\", err)\n\t}\n\n\tif s.cfg.TLS == nil {\n\t\treturn nil\n\t}\n\n\t// TLS is configured: create the TLSAuth middleware for agents and bouncers\n\n\tcacheExpiration := time.Hour\n\tif s.cfg.TLS.CacheExpiration != nil {\n\t\tcacheExpiration = *s.cfg.TLS.CacheExpiration\n\t}\n\n\ts.controller.HandlerV1.Middlewares.JWT.TlsAuth, err = v1.NewTLSAuth(s.cfg.TLS.AllowedAgentsOU, s.cfg.TLS.CRLPath,\n\t\tcacheExpiration,\n\t\tlog.WithFields(log.Fields{\n\t\t\t\"component\": \"tls-auth\",\n\t\t\t\"type\":      \"agent\",","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apiserver.go#L530-L566","documentation":"InitController wraps controller.Init(), which registers all LAPI routes and middlewares on the gin router (and may run DB auto-migrations). A failure here means the API surface could not be built — commonly a database error during route/controller setup.","triggerScenarios":"InitController called after NewServer when the underlying controller.Init fails: DB session errors (e.g. MySQL/Postgres gone after startup), failure loading profiles, or middleware init problems.","commonSituations":"DB dropped/restarted between NewServer and InitController; bad profiles.yaml; driver/migration issues with an unsupported DB version.","solutions":["Read the wrapped cause — it identifies whether DB, profiles, or routes failed.","Verify DB connectivity: `cscli lapi status` or `cscli alerts list`.","Validate profiles.yaml syntax and referenced filters.","Check DB server version compatibility with the crowdsec driver."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before InitController, verify DB session is alive\nif err := server.PingDB(ctx); err != nil { // or cscli lapi status\n    return fmt.Errorf(\"DB not ready: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := server.InitController(); err != nil {\n    if strings.Contains(err.Error(), \"controller init\") && isDBError(err) {\n        // wait and retry once the DB is back\n        time.Sleep(5 * time.Second)\n        return server.InitController()\n    }\n    return err\n}","preventionTips":["Ensure the DB starts before crowdsec (systemd After=/Requires=).","Validate profiles.yaml on deploy.","Pin supported DB versions for your crowdsec release.","Health-check the DB before starting LAPI in containers."],"tags":["lapi","controller","initialization"],"backgroundTag":"database-query-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}