vxcontrol/pentagi · error

database status update failed during container stop: %w

Error message

database status update failed during container stop: %w

What it means

StopContainer successfully stopped (or already found stopped) the Docker container, but persisting the new status (ContainerStatusStopped) to the database failed. The container is down, but the DB row is stale.

Source

Thrown at backend/pkg/docker/client.go:743

func (dc *dockerClient) StopContainer(ctx context.Context, containerID string, dbID int64) error {
	logger := dc.logger.WithContext(ctx).WithField("local_id", containerID)
	logger.Info("initiating container shutdown sequence")

	_, stopErr := dc.client.ContainerStop(ctx, containerID, client.ContainerStopOptions{})
	if stopErr != nil {
		if cerrdefs.IsNotFound(stopErr) {
			logger.Warn("target container already removed or never existed")
		} else {
			return fmt.Errorf("container shutdown failed: %w", stopErr)
		}
	}

	_, err := dc.db.UpdateContainerStatus(ctx, database.UpdateContainerStatusParams{
		Status: database.ContainerStatusStopped,
		ID:     dbID,
	})
	if err != nil {
		return fmt.Errorf("database status update failed during container stop: %w", err)
	}

	logger.Info("container shutdown completed successfully")

	return nil
}

func (dc *dockerClient) RemoveContainer(ctx context.Context, containerID string, dbID int64) error {
	logger := dc.logger.WithContext(ctx).WithField("local_id", containerID)
	logger.Info("removing container and associated resources")

	if err := dc.StopContainer(ctx, containerID, dbID); err != nil {
		return fmt.Errorf("failed to stop container: %w", err)
	}

	options := client.ContainerRemoveOptions{
		RemoveVolumes: true,
		Force:         true,

View on GitHub (pinned to ea665308ba)

Solutions

  1. Check database connectivity and pool health (`SELECT 1` from the backend host)
  2. Look for locks on the containers row (`pg_locks` join `pg_stat_activity`) and resolve the blocking transaction
  3. Retry the status update with a short backoff; the container is already stopped so only the DB write is pending
  4. If the row was deleted concurrently, treat the stop as effectively complete and ignore the missing-row error
Defensive patterns

Strategy: retry

Try / catch

if err := dc.StopContainer(ctx, id, dbID); err != nil {
    var dbErr *pgconn.PgError
    if errors.As(err, &dbErr) && isTransient(dbErr.Code) {
        // retry status update with backoff; container already stopped
    }
}

Prevention

When it happens

Trigger: dc.db.UpdateContainerStatus with Status=ContainerStatusStopped returns an error: DB connection lost, transaction deadlock, row locked by a concurrent update, or the container row was deleted concurrently (foreign-key/row missing).

Common situations: PostgreSQL restart or connection-pool exhaustion during shutdown; concurrent RemoveContainer calls racing on the same dbID; migration running that locks the containers table; network partition between backend and Postgres.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/7bbc33961055887f. Report an issue: GitHub.