crowdsecurity/crowdsec · error
unable to update bouncer ip address in database: %w
Error message
unable to update bouncer ip address in database: %w
What it means
UpdateBouncerIP wraps a failed ent update of a bouncer's ip_address column. UpdateOneID(id).SetIPAddress(ipAddr).Save(ctx) fails on driver errors, missing rows, or cancelled contexts and is wrapped with this message. Called from the LAPI Middleware when a bouncer authenticates.
Source
Thrown at pkg/database/bouncers.go:158
return nil
}
func (c *Client) UpdateBouncerStreamPull(ctx context.Context, lastPull time.Time, streamCursor int, id int) error {
_, err := c.Ent.Bouncer.UpdateOneID(id).
SetLastPull(lastPull).
SetStreamCursor(streamCursor).
Save(ctx)
if err != nil {
return fmt.Errorf("unable to update bouncer stream pull in database: %w", err)
}
return nil
}
func (c *Client) UpdateBouncerIP(ctx context.Context, ipAddr string, id int) error {
_, err := c.Ent.Bouncer.UpdateOneID(id).SetIPAddress(ipAddr).Save(ctx)
if err != nil {
return fmt.Errorf("unable to update bouncer ip address in database: %w", err)
}
return nil
}
func (c *Client) UpdateBouncerTypeAndVersion(ctx context.Context, bType string, version string, id int) error {
_, err := c.Ent.Bouncer.UpdateOneID(id).SetVersion(version).SetType(bType).Save(ctx)
if err != nil {
return fmt.Errorf("unable to update bouncer type and version in database: %w", err)
}
return nil
}
func (c *Client) QueryBouncersInactiveSince(ctx context.Context, t time.Time) ([]*ent.Bouncer, error) {
return c.Ent.Bouncer.Query().Where(
// poor man's coalesce
bouncer.Or(View on GitHub (pinned to 909b515798)
Solutions
- Confirm the bouncer still exists (check cscli bouncers list)
- Retry the update; inspect the wrapped driver error for the real cause
- Check SQLite locking/WAL configuration under concurrent access
- Validate the IP string format before persisting
Defensive patterns
Strategy: try-catch
Validate before calling
if net.ParseIP(ipAddr) == nil { return errors.New("invalid bouncer IP") } Try / catch
if err := c.UpdateBouncerIP(ctx, ip, id); err != nil {
if ent.IsNotFound(errors.Unwrap(err)) { return middleware.ErrBouncerDeleted }
return fmt.Errorf("middleware bouncer ip update: %w", err)
} Prevention
- Normalize the IP (RemoteAddr host part) before persisting
- Don't prune bouncers on every startup without grace period
- Retry transient driver errors in middleware
- Validate ipAddr with net.ParseIP first
When it happens
Trigger: Bouncer ID no longer exists, database unavailable or locked, or the IP string violates a column constraint; also fires when context is cancelled.
Common situations: Bouncer pruned between authentication and the middleware update; 'database is locked' under load; IPv6-mapped addresses being written to a constrained column.
Related errors
- unable to update bouncer type and version in database: %w
- unable to delete bouncers: %w
- unable to update machine last pull in database: %w
- unable to update bouncer stream pull in database: %w
- while getting allowlist %s: %s
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/3138fae6f8e53b6f.
Report an issue: GitHub.