crowdsecurity/crowdsec · error · QueryFail
querying pending machines: %w: %w
Error message
querying pending machines: %w: %w
What it means
QueryPendingMachine wraps QueryFail when querying all machines with is_validated=false fails in the ent layer. This read backs the LAPI prune routine that expires unvalidated pending machines. The wrapped err contains the SQL-level reason.
Source
Thrown at pkg/database/machines.go:156
func (c *Client) ValidateMachine(ctx context.Context, machineID string) error {
rets, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetIsValidated(true).Save(ctx)
if err != nil {
return fmt.Errorf("validating machine: %w: %w", err, UpdateFail)
}
if rets == 0 {
return errors.New("machine not found")
}
return nil
}
func (c *Client) QueryPendingMachine(ctx context.Context) ([]*ent.Machine, error) {
machines, err := c.Ent.Machine.Query().Where(machine.IsValidatedEQ(false)).All(ctx)
if err != nil {
c.Log.Warningf("QueryPendingMachine : %s", err)
return nil, fmt.Errorf("querying pending machines: %w: %w", err, QueryFail)
}
return machines, nil
}
func (c *Client) DeleteWatcher(ctx context.Context, name string) error {
nbDeleted, err := c.Ent.Machine.
Delete().
Where(machine.MachineIdEQ(name)).
Exec(ctx)
if err != nil {
return err
}
if nbDeleted == 0 {
return &MachineNotFoundError{MachineID: name}
}
View on GitHub (pinned to 909b515798)
Solutions
- Inspect the wrapped error and the 'QueryPendingMachine : <err>' warning log
- Ensure the DB is reachable before LAPI starts (depends_on/healthcheck in containers)
- Run `cscli migration` to align schema with the binary
- Check SQLite lock contention; move to Postgres/MySQL for concurrent writers
- Verify prune job config if it fires during maintenance windows
Defensive patterns
Strategy: retry
Validate before calling
// wait for DB before starting prune-dependent jobs
for i := 0; i < 5; i++ { if dbOK(ctx) { break }; time.Sleep(2*time.Second) } Try / catch
pending, err := db.QueryPendingMachine(ctx)
if err != nil {
log.Warnf("prune skipped: %v", err)
return // retry next tick; do not crash the job
} Prevention
- Delay LAPI startup until the DB accepts connections
- Do not downgrade the binary below the migrated schema
- Schedule prune away from backup windows that lock SQLite
- Consider MySQL/Postgres when multiple processes share the DB
When it happens
Trigger: Client.QueryPendingMachine, invoked from the prune job, hits an unavailable DB, a locked SQLite file, or a machines table missing the is_validated column (schema drift).
Common situations: LAPI started before DB is ready (container orchestration race); DB schema migrated backwards; long-running backup holding the SQLite lock; remote DB network blip.
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
- fail to count decisions: %w
- fail to get decision: %w
- listing machines: %w: %w
- no database configuration provided
- unable to update
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/6eac729798a0df26.
Report an issue: GitHub.