crowdsecurity/crowdsec · error
unable to update
Error message
unable to update
What it means
UpdateFail is a sentinel error from crowdsec's database layer meaning an UPDATE/SAVE operation against the persistent store failed. It is wrapped around the underlying ent ORM error (or returned alone) whenever a machine record cannot be created/validated/updated, so callers can match it with errors.Is while the root cause stays wrapped.
Source
Thrown at pkg/database/errors.go:11
package database
import "errors"
var (
UserExists = errors.New("user already exist")
UserNotExists = errors.New("user doesn't exist")
HashError = errors.New("unable to hash")
InsertFail = errors.New("unable to insert row")
QueryFail = errors.New("unable to query")
UpdateFail = errors.New("unable to update")
DeleteFail = errors.New("unable to delete")
ItemNotFound = errors.New("object not found")
ParseTimeFail = errors.New("unable to parse time")
ParseDurationFail = errors.New("unable to parse duration")
MarshalFail = errors.New("unable to serialize")
BulkError = errors.New("unable to insert bulk")
ParseType = errors.New("unable to parse type")
InvalidIPOrRange = errors.New("invalid ip address / range")
InvalidFilter = errors.New("invalid filter")
)
View on GitHub (pinned to 909b515798)
Solutions
- Check the wrapped inner error in the log line (CreateMachine : %s) for the root cause (constraint, connectivity).
- Verify database connectivity and credentials in crowdsec's db_config.
- If registering a duplicate machine, delete or reuse the existing entry (cscli machines list / machines delete) before re-adding.
- Run cscli with a migrated schema (cscli machines/migrations current) to rule out schema drift.
Example fix
// before
m, err := client.CreateMachine(ctx, machineID)
// err: machine 'xxx': unable to update
// after
existing, _ := client.QueryMachineByID(ctx, *machineID)
if existing != nil {
// reuse or delete existing machine before creating
return client.UpdateMachine(ctx, *machineID)
}
m, err := client.CreateMachine(ctx, machineID) Defensive patterns
Strategy: try-catch
Validate before calling
// Go: check DB reachability and duplicate before creating
if _, err := client.QueryMachineByID(ctx, *machineID); err == nil {
return fmt.Errorf("machine %s already exists", *machineID)
}
if err := db.PingContext(ctx); err != nil {
return fmt.Errorf("db unavailable: %w", err)
} Type guard
func isUpdateFail(err error) bool { return errors.Is(err, database.UpdateFail) } Try / catch
if _, err := client.CreateMachine(ctx, machineID); err != nil {
if errors.Is(err, database.UpdateFail) {
log.Warnf("machine write failed (db issue?): %v", err)
return retryLater
}
return err
} Prevention
- Pre-check for duplicate machine IDs before registering
- Monitor database connectivity; set reasonable timeouts in db_config
- Keep schema migrated to the binary's version
When it happens
Trigger: CreateMachine when machine.MachineIdEQ(...).Save(ctx) fails (e.g. duplicate machine_id unique constraint, DB connection lost); ValidateMachine when SetIsValidated(true).Save fails; UpdateMachineLastHeartBeat when the heartbeat update fails.
Common situations: Registering a machine whose ID already exists in the DB (duplicate cscli machine add), transient database outage or connection pool exhaustion during machine validation, migration/schema mismatch between the binary and the DB.
Related errors
- no database configuration provided
- unable to delete
- object not found
- unable to parse time
- unable to parse duration
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/d5d063ba5d522881.
Report an issue: GitHub.