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

  1. Confirm the bouncer still exists (check cscli bouncers list)
  2. Retry the update; inspect the wrapped driver error for the real cause
  3. Check SQLite locking/WAL configuration under concurrent access
  4. 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

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


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/3138fae6f8e53b6f. Report an issue: GitHub.