crowdsecurity/crowdsec · error
while getting decision: %w
Error message
while getting decision: %w
What it means
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.
Source
Thrown at pkg/apiserver/apic.go:926
if ent.IsNotFound(err) {
log.Debugf("no alert found for %s, force refresh", *blocklist.Name)
return true, nil
}
return false, fmt.Errorf("while getting alert: %w", err)
}
decisionQuery := a.dbClient.Ent.Decision.Query()
decisionQuery.Where(decision.HasOwnerWith(alert.IDEQ(alertInstance.ID)))
firstDecision, err := decisionQuery.First(ctx)
if err != nil {
if ent.IsNotFound(err) {
log.Debugf("no decision found for %s, force refresh", *blocklist.Name)
return true, nil
}
return false, fmt.Errorf("while getting decision: %w", err)
}
if firstDecision == nil || firstDecision.Until == nil || firstDecision.Until.Sub(time.Now().UTC()) < (a.pullInterval+15*time.Minute) {
log.Debugf("at least one decision found for %s, expire soon, force refresh", *blocklist.Name)
return true, nil
}
return false, nil
}
func (a *apic) updateBlocklist(ctx context.Context, client *apiclient.ApiClient, blocklist *modelscapi.BlocklistLink, addCounters map[string]map[string]int, forcePull bool) error {
if blocklist.Scope == nil {
log.Warningf("blocklist has no scope")
return nil
}
if blocklist.Duration == nil {
log.Warningf("blocklist has no duration")View on GitHub (pinned to 909b515798)
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.
Defensive patterns
Strategy: retry
Validate before calling
// check DB health first: cscli db doctor
Try / catch
firstDecision, err := decisionQuery.First(ctx)
if err != nil {
if ent.IsNotFound(err) { return true, nil }
return false, fmt.Errorf("while getting decision: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: DB connection dropped between the two queries, slow storage timing out, SQLite locked during concurrent decision inserts.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- while getting alert: %w
- unable to query alerts for uuid %s: %w
- select config item: %w: %w
- expired decisions: %w
- expire decisions with provided filter: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/b27b55ce1447a99e.
Report an issue: GitHub.