crowdsecurity/crowdsec · error
unable to create bouncer: %w
Error message
unable to create bouncer: %w
What it means
CreateBouncer's non-constraint error path: the ent Save failed for any reason other than a uniqueness constraint (DB locked, IO error, connection failure for a client-server DB). The bouncer was not created and no key was issued.
Source
Thrown at pkg/database/bouncers.go:96
return result, nil
}
func (c *Client) CreateBouncer(ctx context.Context, name string, ipAddr string, apiKey string, authType string, autoCreated bool) (*ent.Bouncer, error) {
bouncer, err := c.Ent.Bouncer.
Create().
SetName(name).
SetAPIKey(apiKey).
SetRevoked(false).
SetAuthType(authType).
SetIPAddress(ipAddr).
SetAutoCreated(autoCreated).
Save(ctx)
if err != nil {
if ent.IsConstraintError(err) {
return nil, fmt.Errorf("bouncer %s already exists", name)
}
return nil, fmt.Errorf("unable to create bouncer: %w", err)
}
return bouncer, nil
}
func (c *Client) DeleteBouncer(ctx context.Context, name string) error {
nbDeleted, err := c.Ent.Bouncer.
Delete().
Where(bouncer.NameEQ(name)).
Exec(ctx)
if err != nil {
return err
}
if nbDeleted == 0 {
return &BouncerNotFoundError{BouncerName: name}
}
View on GitHub (pinned to 909b515798)
Solutions
- Read the wrapped error to identify the root cause (lock, permissions, missing table)
- Check DB file ownership/permissions so the crowdsec user can write
- Free disk space if the filesystem is full
- Run the DB migration if the schema is older than the binary
Defensive patterns
Strategy: try-catch
Validate before calling
if err := canWriteDB(dbPath); err != nil {
return fmt.Errorf("database not writable, cannot create bouncer: %w", err)
} Try / catch
b, err := c.CreateBouncer(ctx, name, ip, key, authType, auto)
if err != nil {
var constraint *ent.ConstraintError
if errors.As(err, &constraint) { /* handled as already-exists */ }
// otherwise: inspect wrapped cause - lock, permissions, schema - before retrying
return fmt.Errorf("bouncer creation failed: %w", err)
} Prevention
- Verify the DB file is writable by the crowdsec user and the disk is not full
- Keep the binary and DB schema versions in sync (run migrations on upgrade)
- Raise SQLite busy_timeout when bouncers register during heavy daemon write load
When it happens
Trigger: Calling CreateBouncer ('cscli bouncers add', bouncer auto-registration via authTLS/authPlain) when the insert fails without being a constraint error - SQLite lock/IO errors, read-only DB file, schema mismatch.
Common situations: DB file permissions changed (crowdsec cannot write), disk full, or binary newer than the schema so the insert references missing columns.
Related errors
- error creating alert: %w: %w
- unable to update base bouncer metrics in database: %w
- unable to insert bulk
- while getting allowlist %s: %s
- while getting alert: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/39554baa9c2cfc83.
Report an issue: GitHub.