{"record":{"id":"7bbc33961055887f","repo":"vxcontrol/pentagi","slug":"database-status-update-failed-during-container-sto","errorCode":null,"errorMessage":"database status update failed during container stop: %w","messagePattern":"database status update failed during container stop: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/docker/client.go","lineNumber":743,"sourceCode":"func (dc *dockerClient) StopContainer(ctx context.Context, containerID string, dbID int64) error {\n\tlogger := dc.logger.WithContext(ctx).WithField(\"local_id\", containerID)\n\tlogger.Info(\"initiating container shutdown sequence\")\n\n\t_, stopErr := dc.client.ContainerStop(ctx, containerID, client.ContainerStopOptions{})\n\tif stopErr != nil {\n\t\tif cerrdefs.IsNotFound(stopErr) {\n\t\t\tlogger.Warn(\"target container already removed or never existed\")\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"container shutdown failed: %w\", stopErr)\n\t\t}\n\t}\n\n\t_, err := dc.db.UpdateContainerStatus(ctx, database.UpdateContainerStatusParams{\n\t\tStatus: database.ContainerStatusStopped,\n\t\tID:     dbID,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"database status update failed during container stop: %w\", err)\n\t}\n\n\tlogger.Info(\"container shutdown completed successfully\")\n\n\treturn nil\n}\n\nfunc (dc *dockerClient) RemoveContainer(ctx context.Context, containerID string, dbID int64) error {\n\tlogger := dc.logger.WithContext(ctx).WithField(\"local_id\", containerID)\n\tlogger.Info(\"removing container and associated resources\")\n\n\tif err := dc.StopContainer(ctx, containerID, dbID); err != nil {\n\t\treturn fmt.Errorf(\"failed to stop container: %w\", err)\n\t}\n\n\toptions := client.ContainerRemoveOptions{\n\t\tRemoveVolumes: true,\n\t\tForce:         true,","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/docker/client.go#L725-L761","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check database connectivity and pool health (`SELECT 1` from the backend host)","Look for locks on the containers row (`pg_locks` join `pg_stat_activity`) and resolve the blocking transaction","Retry the status update with a short backoff; the container is already stopped so only the DB write is pending","If the row was deleted concurrently, treat the stop as effectively complete and ignore the missing-row error"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := dc.StopContainer(ctx, id, dbID); err != nil {\n    var dbErr *pgconn.PgError\n    if errors.As(err, &dbErr) && isTransient(dbErr.Code) {\n        // retry status update with backoff; container already stopped\n    }\n}","preventionTips":["Keep the DB connection pool sized for teardown bursts","Avoid holding long transactions over the containers table","Use short retry with backoff for status updates","Treat missing-row errors during concurrent teardown as benign"],"tags":["database","postgresql","container-lifecycle"],"backgroundTag":"database-update-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}