{"record":{"id":"f8260729cc55f27d","repo":"crowdsecurity/crowdsec","slug":"while-getting-allowlist-s-s","errorCode":null,"errorMessage":"while getting allowlist %s: %s","messagePattern":"while getting allowlist (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/apic.go","lineNumber":762,"sourceCode":"\n\tscanner := bufio.NewScanner(resp.Body)\n\titems := make([]*models.AllowlistItem, 0)\n\n\tfor scanner.Scan() {\n\t\titem := scanner.Text()\n\t\tj := &models.AllowlistItem{}\n\n\t\tif err := json.Unmarshal([]byte(item), j); err != nil {\n\t\t\treturn fmt.Errorf(\"while unmarshalling allowlist item: %s\", err)\n\t\t}\n\n\t\titems = append(items, j)\n\t}\n\n\tlist, err := a.dbClient.GetAllowListByID(ctx, *link.ID, false)\n\tif err != nil {\n\t\tif !ent.IsNotFound(err) {\n\t\t\treturn fmt.Errorf(\"while getting allowlist %s: %s\", *link.Name, err)\n\t\t}\n\t}\n\n\tif list == nil {\n\t\tlist, err = a.dbClient.CreateAllowList(ctx, *link.Name, description, *link.ID, true)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"while creating allowlist %s: %s\", *link.Name, err)\n\t\t}\n\t}\n\n\tadded, err := a.dbClient.ReplaceAllowlist(ctx, list, items, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while replacing allowlist %s: %s\", *link.Name, err)\n\t}\n\n\tlog.Infof(\"added %d values to allowlist %s\", added, list.Name)\n\n\tif list.Name != *link.Name || list.Description != description {","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apic.go#L744-L780","documentation":"After parsing the items, updateOneAllowlist looks up the existing allowlist in the local database with GetAllowListByID(link.ID). This error wraps any DB error other than ent's NotFound (NotFound is tolerated because the list may legitimately not exist yet). It signals a real database-level failure, not a missing record.","triggerScenarios":"GetAllowListByID fails with a non-NotFound error: database unreachable/closed connection, SQL error, transaction/timeout, or corruption when querying the allowlists table by ID.","commonSituations":"SQLite file locked or on a full disk; stale DB connection after a long outage; DB schema migration mismatch after upgrading crowdsec; running crowdsec while the DB is being backed up or another process holds a write lock.","solutions":["Inspect the wrapped %s message to identify the underlying DB error","Verify DB connectivity: check crowdsec can open its DB (cscli dbstatus or logs)","If SQLite: ensure no stale lock and sufficient disk space; restart crowdsec to reconnect","Run cscli db migrate / upgrade properly if versions are mismatched","If persistent, restore or recreate the database from backups"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before sync, verify the DB is reachable and writable\nif err := dbClient.Client().Debug().Ping(ctx); err != nil {\n    return fmt.Errorf(\"database unreachable before allowlist sync: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := a.updateOneAllowlist(ctx, client, link)\nif err != nil && strings.Contains(err.Error(), \"while getting allowlist\") {\n    if ent.IsNotFoundError(err) {\n        // tolerated: list will be created\n        return nil\n    }\n    log.Errorf(\"allowlist DB lookup failed, will retry on next cycle: %s\", err)\n}","preventionTips":["Keep adequate free disk space for the SQLite DB","Avoid running DB backups/vacuum while crowdsec is syncing","Restart crowdsec after prolonged outages to reset stale DB connections","Follow the supported upgrade path so the schema matches the binary version"],"tags":["database","allowlist","ent","sqlite"],"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"}