crowdsecurity/crowdsec · error

unable to update bouncer type and version in database: %w

Error message

unable to update bouncer type and version in database: %w

What it means

UpdateBouncerTypeAndVersion wraps a failed ent update of a bouncer's type and version columns. Called from the LAPI Middleware so the database reflects the authenticating bouncer's reported type/version; any update failure is wrapped with this message.

Source

Thrown at pkg/database/bouncers.go:167

		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(
			bouncer.LastPullLT(t),
			bouncer.And(
				bouncer.LastPullIsNil(),
				bouncer.CreatedAtLT(t),
			),
		),
	).All(ctx)
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Verify the bouncer entry still exists before/after update (ent.IsNotFound)
  2. Inspect the wrapped driver error and retry transient failures
  3. Check SQLite lock contention and WAL mode
  4. Confirm the middleware's context isn't cancelled by client disconnect
Defensive patterns

Strategy: try-catch

Validate before calling

if n, _ := c.Ent.Bouncer.Query().Where(bouncer.ID(id)).Count(ctx); n == 0 { return }

Try / catch

if err := c.UpdateBouncerTypeAndVersion(ctx, bType, version, id); err != nil {
	log.Warnf("bouncer %d type/version update failed: %v", id, err)
}

Prevention

When it happens

Trigger: Bouncer row deleted concurrently (e.g. by prune), database locked/unreachable, or context cancelled during the UPDATE.

Common situations: A newly upgraded bouncer re-authenticates while cscli/prune removes stale entries; SQLite contention on busy LAPI instances.

Related errors


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