{"record":{"id":"b27b55ce1447a99e","repo":"crowdsecurity/crowdsec","slug":"while-getting-decision-w","errorCode":null,"errorMessage":"while getting decision: %w","messagePattern":"while getting decision: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/apic.go","lineNumber":926,"sourceCode":"\t\tif ent.IsNotFound(err) {\n\t\t\tlog.Debugf(\"no alert found for %s, force refresh\", *blocklist.Name)\n\t\t\treturn true, nil\n\t\t}\n\n\t\treturn false, fmt.Errorf(\"while getting alert: %w\", err)\n\t}\n\n\tdecisionQuery := a.dbClient.Ent.Decision.Query()\n\tdecisionQuery.Where(decision.HasOwnerWith(alert.IDEQ(alertInstance.ID)))\n\n\tfirstDecision, err := decisionQuery.First(ctx)\n\tif err != nil {\n\t\tif ent.IsNotFound(err) {\n\t\t\tlog.Debugf(\"no decision found for %s, force refresh\", *blocklist.Name)\n\t\t\treturn true, nil\n\t\t}\n\n\t\treturn false, fmt.Errorf(\"while getting decision: %w\", err)\n\t}\n\n\tif firstDecision == nil || firstDecision.Until == nil || firstDecision.Until.Sub(time.Now().UTC()) < (a.pullInterval+15*time.Minute) {\n\t\tlog.Debugf(\"at least one decision found for %s, expire soon, force refresh\", *blocklist.Name)\n\t\treturn true, nil\n\t}\n\n\treturn false, nil\n}\n\nfunc (a *apic) updateBlocklist(ctx context.Context, client *apiclient.ApiClient, blocklist *modelscapi.BlocklistLink, addCounters map[string]map[string]int, forcePull bool) error {\n\tif blocklist.Scope == nil {\n\t\tlog.Warningf(\"blocklist has no scope\")\n\t\treturn nil\n\t}\n\n\tif blocklist.Duration == nil {\n\t\tlog.Warningf(\"blocklist has no duration\")","sourceCodeStart":908,"sourceCodeEnd":944,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/apic.go#L908-L944","documentation":"Same function, second stage: wraps the error from fetching the newest decision owned by the blocklist's last alert. NotFound means no decisions exist and triggers a forced refresh; other errors (DB failure, cancelled context) are wrapped here.","triggerScenarios":"The decision query `Decision.Query().Where(HasOwnerWith(alert.IDEQ(...))).First(ctx)` fails with a non-NotFound error: DB unavailability, context deadline, or ent query error.","commonSituations":"DB connection dropped between the two queries, slow storage timing out, SQLite locked during concurrent decision inserts.","solutions":["Inspect the wrapped error; run `cscli db doctor` to check DB health.","Enable SQLite WAL mode to reduce lock contention.","Check for context timeout configuration if errors are deadline-exceeded.","Retry the blocklist pull cycle."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// check DB health first: cscli db doctor","typeGuard":null,"tryCatchPattern":"firstDecision, err := decisionQuery.First(ctx)\nif err != nil {\n    if ent.IsNotFound(err) { return true, nil }\n    return false, fmt.Errorf(\"while getting decision: %w\", err)\n}","preventionTips":["Enable WAL mode to reduce SQLite contention during decision inserts.","Ensure pull cycles are not cancelled mid-query (graceful shutdown).","Keep the decision/alert schema up to date via migrations."],"tags":["database","ent","query","blocklist","decisions"],"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"}